private void RunClientServerTest() { const ushort port = 5321; var listener = new TcpStubListener <SimpleMessage <int>, int>(new SimpleMessageSerializer <int>(BinarySerializerService.GetSerializer <int>()), new SingleThreadedTimerService()); var endPoint = new IPEndPoint(IPAddress.Any, port); listener.BindTo(endPoint); var serverTask = Task.Run(() => AcceptSocket(listener)); var connectionBuilder = new TcpStubBuilder <SimpleMessage <int>, int>(new SimpleMessageSerializer <int>(BinarySerializerService.GetSerializer <int>()), new SingleThreadedTimerService()); var ep = new IPEndPoint(IPAddress.Loopback, port); Console.WriteLine(@"Client: Building connection to {0}", ep); var connection = connectionBuilder.Build(ep); Console.WriteLine(@"Client: Sending Hello"); connection.Write(new SimpleMessage <int>(0, Encoding.ASCII.GetBytes("Hello"))); Console.WriteLine(@"Client: Reading response"); int size; var response = connection.ReadNext(out size); if (null == response) { Console.WriteLine(@"Received null from connection"); connection.Dispose(); return; } Console.WriteLine(@"Client: Read {0} bytes", size); Console.WriteLine(@"Client: Got Response; contents: {0}", Encoding.ASCII.GetString(response.Data)); Console.WriteLine(@"Client: Done, exiting"); connection.Dispose(); serverTask.Wait(); Console.WriteLine(); Console.WriteLine(@"Press any key to exit"); Console.ReadKey(); }
private void RunSubscriberTest() { var listener = new TcpStubListener<SimpleMessage<int>, int>(new SimpleMessageSerializer<int>(BinarySerializerService.GetSerializer<int>()), new SingleThreadedTimerService()); const ushort port = 50124; var connection = new StubConnection<SimpleMessage<int>, int>( new ThreadManager(RuntimeCommon.DefaultLogger), new TcpStubBuilder<SimpleMessage<int>, int>(new SimpleMessageSerializer<int>(BinarySerializerService.GetSerializer<int>()), new SingleThreadedTimerService())); RunClientSubscriber(connection, listener, port); }
private void RunSubscriberTest() { var listener = new TcpStubListener <SimpleMessage <int>, int>(new SimpleMessageSerializer <int>(BinarySerializerService.GetSerializer <int>()), new SingleThreadedTimerService()); const ushort port = 50124; var connection = new StubConnection <SimpleMessage <int>, int>( new ThreadManager(RuntimeCommon.DefaultLogger), new TcpStubBuilder <SimpleMessage <int>, int>(new SimpleMessageSerializer <int>(BinarySerializerService.GetSerializer <int>()), new SingleThreadedTimerService())); RunClientSubscriber(connection, listener, port); }
private void RunClientServerTest() { const ushort port = 5321; var listener = new TcpStubListener<SimpleMessage<int>, int>(new SimpleMessageSerializer<int>(BinarySerializerService.GetSerializer<int>()), new SingleThreadedTimerService()); var endPoint = new IPEndPoint(IPAddress.Any, port); listener.BindTo(endPoint); var serverTask = Task.Run(() => AcceptSocket(listener)); var connectionBuilder = new TcpStubBuilder<SimpleMessage<int>, int>(new SimpleMessageSerializer<int>(BinarySerializerService.GetSerializer<int>()), new SingleThreadedTimerService()); var ep = new IPEndPoint(IPAddress.Loopback, port); Console.WriteLine(@"Client: Building connection to {0}", ep); var connection = connectionBuilder.Build(ep); Console.WriteLine(@"Client: Sending Hello"); connection.Write(new SimpleMessage<int>(0, Encoding.ASCII.GetBytes("Hello"))); Console.WriteLine(@"Client: Reading response"); int size; var response = connection.ReadNext(out size); if (null == response) { Console.WriteLine(@"Received null from connection"); connection.Dispose(); return; } Console.WriteLine(@"Client: Read {0} bytes", size); Console.WriteLine(@"Client: Got Response; contents: {0}", Encoding.ASCII.GetString(response.Data)); Console.WriteLine(@"Client: Done, exiting"); connection.Dispose(); serverTask.Wait(); Console.WriteLine(); Console.WriteLine(@"Press any key to exit"); Console.ReadKey(); }