using System.Threading.Tasks;
await new Duplex().RunAsync();
public async Task RunAsync()
var server = new NamedPipeServerStream("JsonRpcDuplex", PipeDirection.InOut, maxNumberOfServerInstances: 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous);
var client = new NamedPipeClientStream(".", "JsonRpcDuplex", PipeDirection.InOut, PipeOptions.Asynchronous);
await Task.WhenAll(server.WaitForConnectionAsync(), client.ConnectAsync()).ConfigureAwait(false);
var s1 = this.Server1(server);
var s2 = this.Server2(client);
IHost2 Server1(Stream send)
var rpc = new JsonRpc(send)
CancelLocallyInvokedMethodsWhenConnectionIsClosed = true
rpc.AddLocalRpcTarget(host, null);
var service2 = rpc.Attach<IHost2>();
IHost1 Server2(Stream send)
var rpc = new JsonRpc(send)
CancelLocallyInvokedMethodsWhenConnectionIsClosed = true
rpc.AddLocalRpcTarget(host, null);
var service1 = rpc.Attach<IHost1>();
public class Host1 : IHost1
Console.WriteLine("Do1");
return Task.CompletedTask;
public class Host2 : IHost2
Console.WriteLine("Do2");
return Task.CompletedTask;