Lightweight .NET Standard 2.0 library to use method calls over named and anonymous pipes for IPC. Supports two-way communication with callbacks.
var pipeServer = new PipeServer<IAdder>(
new NetJsonPipeSerializer(),
"mypipe",
() => new Adder());
await pipeServer.WaitForConnectionAsync();
var pipeClient = new PipeClient<IAdder>(new NetJsonPipeSerializer(), "mypipe");
await pipeClient.ConnectAsync();
int result = await pipeClient.InvokeAsync(adder => adder.AddNumbers(1, 3));
var pipeServer = new PipeServerWithCallback<IConcatenator, IAdder>(
new NetJsonPipeSerializer(),
"mypipe",
() => new Adder());
await pipeServer.WaitForConnectionAsync();
string concatResult = await pipeServer.InvokeAsync(c => c.Concatenate("a", "b"));
var pipeClient = new PipeClientWithCallback<IAdder, IConcatenator>(
new NetJsonPipeSerializer(),
"mypipe",
() => new Concatenator());
await pipeClient.ConnectAsync();
int result = await pipeClient.InvokeAsync(a => a.AddNumbers(4, 7));
This library uses named pipes to invoke method calls on a remote endpoint. The method arguments are serialized to binary and sent over the pipe.
PipeMethodCalls supports customizable serialization logic through IPipeSerializer
. You've got two options:
- Use a pre-built serializer
new NetJsonPipeSerializer()
from the PipeMethodCalls.NetJson package. That uses the System.Text.Json serializer that's built into .NET.new MessagePackPipeSerializer()
from the PipeMethodCalls.MessagePack package. That uses the MessagePack-CSharp serializer, which has excellent performance.
- Plug in your own implementation of
IPipeSerializer
. Refer to the NetJsonPipeSerializer code for an example of how to do this.
Open an issue or pull request if you'd like to see more built-in serializers.
- 100% asynchronous communication with .ConfigureAwait(false) to minimize context switches and reduce thread use
- 45KB with no built-in dependencies
- Invoking async methods
- Passing and returning complex types with pluggable JSON or binary serialization
- Interleaved or multiple simultaneous calls
- Throwing exceptions
- CancellationToken support
- Works on Windows, Linux and MacOS
- Methods with out and ref parameters
- Properties
- Method overloads