A simple, easy to use, strongly-typed, async wrapper around .NET named pipes.
- Create named pipe servers that can handle multiple client connections simultaneously.
- Send strongly-typed messages between clients and servers: any serializable .NET object can be sent over a pipe and will be automatically serialized/deserialized, including cyclical references and complex object graphs.
- Async
- Requires .NET Standard 2.0
- Supports large messages - up to 300 MiB.
- Server restart automatically
- Automatically wait for the release of the pipe for the server, if it is already in use
- Automatically waiting for a pipe creating when client connecting
- Automatic reconnect with a given interval and at each
client.WriteAsync
, if necessary - Supports variable formatters, default - BinaryFormatter which uses System.Runtime.Serialization.BinaryFormatter inside
Server:
await using var server = new PipeServer<MyMessage>(pipeName);
server.ClientConnected += async (o, args) =>
{
Console.WriteLine($"Client {args.Connection.Id} is now connected!");
await args.Connection.WriteAsync(new MyMessage
{
Id = new Random().Next(),
Text = "Welcome!"
});
};
server.ClientDisconnected += (o, args) =>
{
Console.WriteLine($"Client {args.Connection.Id} disconnected");
};
server.MessageReceived += (sender, args) =>
{
Console.WriteLine($"Client {args.Connection.Id} says: {args.Message}");
};
server.ExceptionOccurred += (o, args) => OnExceptionOccurred(args.Exception);
await server.StartAsync();
await Task.Delay(Timeout.InfiniteTimeSpan);
Client:
await using var client = new PipeClient<MyMessage>(pipeName);
client.MessageReceived += (o, args) => Console.WriteLine("MessageReceived: " + args.Message);
client.Disconnected += (o, args) => Console.WriteLine("Disconnected from server");
client.Connected += (o, args) => Console.WriteLine("Connected to server");
client.ExceptionOccurred += (o, args) => OnExceptionOccurred(args.Exception);
await client.ConnectAsync();
await client.WriteAsync(new MyMessage
{
Id = new Random().Next(),
Text = "Hello!",
});
await Task.Delay(Timeout.InfiniteTimeSpan);