public async Task MultipleClientsWork(ChannelType type) { var proxy = await Init <ITestObject>(new TestObject(), type); ITestObject proxy2 = null; if (type == ChannelType.Tcp) { var client2 = new TcpRpcClientChannel( new BinaryRpcSerializer(), new RpcMessageFactory(), IPAddress.Loopback, 11234); await client2.ConnectAsync(); proxy2 = await client2.GetServerObjectAsync <ITestObject>(); } else if (type == ChannelType.NamedPipe) { var client2 = new NamedPipeRpcClientChannel( new BinaryRpcSerializer(), new RpcMessageFactory(), _pipeName); await client2.ConnectAsync(); proxy2 = await client2.GetServerObjectAsync <ITestObject>(); } var threads = new List <Task <bool> >(); for (int i = 0; i < 10; i++) { int mi = i; threads.Add(new Task <bool>(delegate { ITestObject pr = mi % 2 == 0 ? proxy : proxy2; for (int j = 0; j < 100; j++) { if (pr.SimpleCalc(mi * 100, j) != mi * 100 + j) { return(false); } } return(true); })); } foreach (var t in threads) { t.Start(); } Assert.IsTrue(Task.WaitAll(threads.ToArray(), 20000)); Assert.IsTrue(threads.TrueForAll(t => t.Result)); }
public async Task TcpRpcClientRaisesEventOnDisconnectWhenServerShutdown() { using (var server = new TcpRpcServerChannel( new BinaryRpcSerializer(), new RpcMessageFactory(), IPAddress.Loopback, 11234)) { await server.ListenAsync(); using (var client = new TcpRpcClientChannel(new BinaryRpcSerializer(), new RpcMessageFactory(), IPAddress.Loopback, 11234)) { await client.ConnectAsync(); var wait = new ManualResetEventSlim(false); client.Disconnected += (s, e) => { Assert.AreSame(client, e.TransportChannel.Channel); wait.Set(); }; server.Dispose(); Assert.IsTrue(wait.Wait(1000)); } } }
private async Task <IRpcClientChannel> CreateClient(ChannelType channelType, IRpcSerializer serializer = null, TokenImpersonationLevel tokenImpersonationLevel = TokenImpersonationLevel.None, IRpcObjectRepository localRepository = null, Func <IRpcObjectRepository> remoteRepository = null) { if (serializer == null) { serializer = new BinaryRpcSerializer(); } switch (channelType) { case ChannelType.Tcp: { var client = new TcpRpcClientChannel( serializer, new RpcMessageFactory(), IPAddress.Loopback, 11234, localRepository, remoteRepository); await client.ConnectAsync(); return(client); } case ChannelType.NamedPipe: { var client = new NamedPipeRpcClientChannel( serializer, new RpcMessageFactory(), _pipeName, tokenImpersonationLevel, localRepository, remoteRepository); await client.ConnectAsync(); return(client); } default: throw new NotSupportedException(); } }
private static void Run(TcpRpcClientChannel client) { client.GetServerObjectAsync <ITestObject>().GetAwaiter().GetResult(); }