static async Task Main(string[] args) { if (args.Length > 0) { var pair = new EnginePair(); pair.Engine1.Main = new CapnpEchoService(); var echoer = (CapabilityReflection.CreateProxy <IEchoer>(pair.Endpoint2.QueryMain()) as IEchoer); await Run(echoer); } else { using var server = new TcpRpcServer(); server.Main = new CapnpEchoService(); server.AddBuffering(); server.StartAccepting(IPAddress.Any, 5002); using var client = new TcpRpcClient(); client.AddBuffering(); client.Connect("localhost", 5002); await client.WhenConnected; using var echoer = client.GetMain <IEchoer>(); await Run(echoer); } }
protected TcpRpcServer SetupServer() { int attempt = 0; while (true) { try { var server = new TcpRpcServer(IPAddress.Any, TcpPort); server.AddBuffering(); return(server); } catch (SocketException) { // If the TCP listening port is occupied by some other process, // retry with a different one if (attempt == 5) { throw; } } IncrementTcpPort(); ++attempt; } }
protected static TcpRpcServer SetupServer(IPAddress addr, int port) { var server = new TcpRpcServer(); server.AddBuffering(); server.StartAccepting(addr, port); return(server); }
static void Main(string[] args) { using (var server = new TcpRpcServer()) { server.AddBuffering(); server.Main = new CapnpEchoService(); server.StartAccepting(IPAddress.Any, 5002); Console.WriteLine("Press RETURN to stop listening"); Console.ReadLine(); } }
static async Task Main(string[] args) { using var server = new TcpRpcServer(); server.Main = new CapnpEchoService(); server.AddBuffering(); server.StartAccepting(IPAddress.Any, 5002); using var client = new TcpRpcClient("localhost", 5002); await client.WhenConnected; using var echoer = client.GetMain <IEchoer>(); var payload = new byte[20]; new Random().NextBytes(payload); while (true) { var result = await echoer.Echo(payload); if (result.Count != payload.Length) { throw new InvalidOperationException("Echo server malfunction"); } } }