public TcpConnectionDemo() { LogProvider.GlobalLogWrite += LogProviderOnLogWrite; EventConsumer serverConsumer = new EventConsumer(); serverConsumer.ClientConnected += ServerConsumerOnClientConnected; serverConsumer.ClientDisconnected += ServerConsumerOnClientDisconnected; serverConsumer.ReceivedPacket += ServerConsumerOnReceivedPacket; AsyncEventServer server = new AsyncEventServer(IPAddress.Any, 2345, serverConsumer); server.Start(); EventConsumer clientConsumer = new EventConsumer(); clientConsumer.ClientConnected += ClientConsumerOnClientConnected; clientConsumer.ClientDisconnected += ClientConsumerOnClientDisconnected; clientConsumer.ReceivedPacket += ClientConsumerOnReceivedPacket; SyncReceiveTcpClient client = new SyncReceiveTcpClient(clientConsumer); client.ConnectError += ClientConsumerOnConnectError; client.Connect(IPAddress.Parse("127.0.0.1"), 2345, TimeSpan.Zero); Console.WriteLine("Demo: Press any key to send."); Console.ReadKey(); client.Send(new byte[9]); Console.WriteLine("Demo: Press any key to disconnect."); Console.ReadKey(); client.Close(); server.Stop(); Console.WriteLine("Demo: Press any key to exit."); Console.ReadKey(); }
public void Disconnect() { _client.Close(); }