Interprocess communication (IPC) library utilizes named pipes to allow communication between different processes running on the same machine.
using var serverPipe = new ServerPipe("EXAMPLE_PIPE", "Example Server", CancellationToken.None)
{
UseDynamicDataPacketSize = true
};
serverPipe.Initialize();
serverPipe.DataReceived += (s, e) =>
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Client [Len = {0}]: {1}", e.Length, Encoding.UTF8.GetString(e.Data));
Console.ResetColor();
};
serverPipe.GotConnectionEvent += (sender, e) =>
{
Console.WriteLine("Server pipe got a new client...");
};
serverPipe.PipeClosed += (_, reason) =>
{
Console.WriteLine("Server pipe got closed ({0})...", reason);
};
await serverPipe.WaitForClientAsync();
...
await serverPipe.WriteAsync(Encoding.UTF8.GetBytes("This is sent from the server!"));
using var clientPipe = new ClientPipe(".", "EXAMPLE_PIPE", "Example Client")
{
UseDynamicDataPacketSize = true
};
clientPipe.DataReceived += (s, e) =>
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Server [Len = {0}]: {1}", e.Length, Encoding.UTF8.GetString(e.Data));
Console.ResetColor();
};
clientPipe.PipeClosed += (_, reason) =>
{
Console.WriteLine("Client pipe got closed ({0})...", reason);
};
await clientPipe.ConnectAsync();
clientPipe.StartReadingAsync(CancellationToken.None);
...
await clientPipe.WriteAsync(Encoding.UTF8.GetBytes("This is sent from the client!"));