Skip to content

Instantly share code, notes, and snippets.

@kristopherjohnson
Created July 4, 2012 14:10
Show Gist options
  • Save kristopherjohnson/3047562 to your computer and use it in GitHub Desktop.
Save kristopherjohnson/3047562 to your computer and use it in GitHub Desktop.
Utility methods for using .NET IpcChannel
using System;
using System.Collections;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Ipc;
using System.Runtime.Serialization.Formatters;
namespace MyLibrary
{
/// <summary>
/// Utility methods to support .NET Remoting with IPC channels
/// </summary>
public static class IpcRemotingUtil
{
/// <summary>
/// Return a new client/server IpcChannel
/// </summary>
/// <param name="portName">IPC port name</param>
/// <returns>IpcChannel</returns>
public static IpcChannel CreateIpcChannel(string portName)
{
var serverSinkProvider = new BinaryServerFormatterSinkProvider();
serverSinkProvider.TypeFilterLevel = TypeFilterLevel.Full;
IDictionary properties = new Hashtable();
properties["portName"] = portName;
properties["authorizedGroup"] = "Everyone";
return new IpcChannel(properties, null, serverSinkProvider);
}
/// <summary>
/// Return a new client/server IpcChannel with a unique IPC port name
/// </summary>
/// <returns>IpcChannel</returns>
public static IpcChannel CreateIpcChannelWithUniquePortName()
{
return CreateIpcChannel(Guid.NewGuid().ToString());
}
}
}
@kristopherjohnson
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment