Пример #1
0
        private static async Task NetServerThread()
        {
            TcpListener listener = new TcpListener(IPAddress.Loopback, lbPort);

            listener.Start();
            _ioClientsReady.SignalAndWait();
            var client = await listener.AcceptTcpClientAsync();

            _serverSock = client;
            using (var rpcServer = new NetworkRpcEndpoint(new TcpTransportLayer(client), JsonRpcEndpoint.EndpointMode.Server))
            {
                rpcServer.RpcLayer.RequestPipeline.AddItemToStart(async(req) =>
                {
                    if (!req.IsNotification)
                    {
                        Console.WriteLine($"Client called method {req.Method}.");
                        return(await Task.FromResult(new ResultResponse(req, "pong")));
                    }
                    return(null);
                });
                _ioClientsReady.SignalAndWait();
                _ioClientsReady.SignalAndWait();
            }
            _serverSock.Dispose();
            listener.Stop();
        }
Пример #2
0
        private static async Task NetClientThread()
        {
            _ioClientsReady.SignalAndWait();
            var client = new TcpClient();

            _clientSock = client;
            await client.ConnectAsync(IPAddress.Loopback, lbPort);

            using (var rpcClient = new NetworkRpcEndpoint(new TcpTransportLayer(client), JsonRpcEndpoint.EndpointMode.Client))
            {
                _ioClientsReady.SignalAndWait();
                var reqTask  = rpcClient.Request(new Request("ping", null, "0"));
                var response = await reqTask;
                Console.WriteLine($"Server responded: {response}");
                _ioClientsReady.SignalAndWait();
            }
            _clientSock.Dispose();
        }
Пример #3
0
 public RpcCaller(NetworkRpcClient netRpcClient)
 {
     RpcClient = netRpcClient;
 }