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(); }
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(); }
public RpcCaller(NetworkRpcClient netRpcClient) { RpcClient = netRpcClient; }