static void Main(string[] args) { NLogLogger.Use(); try { var config = new TcpSocketSaeaClientConfiguration(); IPEndPoint remoteEP = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 22222); _client = new TcpSocketSaeaClient(remoteEP, new SimpleMessageDispatcher(), config); _client.Connect().Wait(); Console.WriteLine("TCP client has connected to server [{0}].", remoteEP); Console.WriteLine("Type something to send to server..."); while (true) { try { string text = Console.ReadLine(); if (text == "quit") { break; } Task.Run(async() => { await _client.SendAsync(Encoding.UTF8.GetBytes(text)); Console.WriteLine("Client [{0}] send text -> [{1}].", _client.LocalEndPoint, text); }); } catch (Exception ex) { Console.WriteLine(ex.Message); } } _client.Close().Wait(); Console.WriteLine("TCP client has disconnected from server [{0}].", remoteEP); } catch (Exception ex) { Logger.Get <Program>().Error(ex.Message, ex); } Console.ReadKey(); }
static void Main(string[] args) { NLogLogger.Use(); try { var config = new TcpSocketSaeaClientConfiguration(); IPEndPoint remoteEP = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 22222); _client = new TcpSocketSaeaClient(remoteEP, new SimpleMessageDispatcher(), config); _client.Connect().Wait(); Console.WriteLine("TCP client has connected to server [{0}].", remoteEP); Console.WriteLine("Type something to send to server..."); while (true) { try { string text = Console.ReadLine(); if (text == "quit") break; Task.Run(async () => { await _client.SendAsync(Encoding.UTF8.GetBytes(text)); Console.WriteLine("Client [{0}] send text -> [{1}].", _client.LocalEndPoint, text); }); } catch (Exception ex) { Console.WriteLine(ex.Message); } } _client.Close().Wait(); Console.WriteLine("TCP client has disconnected from server [{0}].", remoteEP); } catch (Exception ex) { Logger.Get<Program>().Error(ex.Message, ex); } Console.ReadKey(); }
static void Main(string[] args) { NLogLogger.Use(); try { var config = new TcpSocketSaeaClientConfiguration(); //config.FrameBuilder = new FixedLengthFrameBuilder(20000); //config.FrameBuilder = new RawBufferFrameBuilder(); //config.FrameBuilder = new LineBasedFrameBuilder(); //config.FrameBuilder = new LengthPrefixedFrameBuilder(); //config.FrameBuilder = new LengthFieldBasedFrameBuilder(); IPEndPoint remoteEP = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 22222); _client = new TcpSocketSaeaClient(remoteEP, new SimpleMessageDispatcher(), config); _client.Connect().Wait(); Console.WriteLine("TCP client has connected to server [{0}].", remoteEP); Console.WriteLine("Type something to send to server..."); while (true) { try { string text = Console.ReadLine(); if (text == "quit") { break; } Task.Run(async() => { if (text == "many") { text = new string('x', 8192); for (int i = 0; i < 1000000; i++) { await _client.SendAsync(Encoding.UTF8.GetBytes(text)); Console.WriteLine("Client [{0}] send text -> [{1}].", _client.LocalEndPoint, text); } } else if (text == "big1k") { text = new string('x', 1024 * 1); await _client.SendAsync(Encoding.UTF8.GetBytes(text)); Console.WriteLine("Client [{0}] send text -> [{1} Bytes].", _client.LocalEndPoint, text.Length); } else if (text == "big10k") { text = new string('x', 1024 * 10); await _client.SendAsync(Encoding.UTF8.GetBytes(text)); Console.WriteLine("Client [{0}] send text -> [{1} Bytes].", _client.LocalEndPoint, text.Length); } else if (text == "big100k") { text = new string('x', 1024 * 100); await _client.SendAsync(Encoding.UTF8.GetBytes(text)); Console.WriteLine("Client [{0}] send text -> [{1} Bytes].", _client.LocalEndPoint, text.Length); } else if (text == "big1m") { text = new string('x', 1024 * 1024 * 1); await _client.SendAsync(Encoding.UTF8.GetBytes(text)); Console.WriteLine("Client [{0}] send text -> [{1} Bytes].", _client.LocalEndPoint, text.Length); } else if (text == "big10m") { text = new string('x', 1024 * 1024 * 10); await _client.SendAsync(Encoding.UTF8.GetBytes(text)); Console.WriteLine("Client [{0}] send text -> [{1} Bytes].", _client.LocalEndPoint, text.Length); } else if (text == "big100m") { text = new string('x', 1024 * 1024 * 100); await _client.SendAsync(Encoding.UTF8.GetBytes(text)); Console.WriteLine("Client [{0}] send text -> [{1} Bytes].", _client.LocalEndPoint, text.Length); } else if (text == "big1g") { text = new string('x', 1024 * 1024 * 1024); await _client.SendAsync(Encoding.UTF8.GetBytes(text)); Console.WriteLine("Client [{0}] send text -> [{1} Bytes].", _client.LocalEndPoint, text.Length); } else { await _client.SendAsync(Encoding.UTF8.GetBytes(text)); Console.WriteLine("Client [{0}] send text -> [{1} Bytes].", _client.LocalEndPoint, text.Length); } }); } catch (Exception ex) { Logger.Get <Program>().Error(ex.Message, ex); } } _client.Close().Wait(); Console.WriteLine("TCP client has disconnected from server [{0}].", remoteEP); } catch (Exception ex) { Logger.Get <Program>().Error(ex.Message, ex); } Console.ReadKey(); }
static void Main(string[] args) { NLogLogger.Use(); try { var config = new TcpSocketSaeaClientConfiguration(); //config.FrameBuilder = new FixedLengthFrameBuilder(20000); //config.FrameBuilder = new RawBufferFrameBuilder(); //config.FrameBuilder = new LineBasedFrameBuilder(); //config.FrameBuilder = new LengthPrefixedFrameBuilder(); //config.FrameBuilder = new LengthFieldBasedFrameBuilder(); IPEndPoint remoteEP = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 22222); _client = new TcpSocketSaeaClient(remoteEP, new SimpleMessageDispatcher(), config); _client.Connect().Wait(); Console.WriteLine("TCP client has connected to server [{0}].", remoteEP); Console.WriteLine("Type something to send to server..."); while (true) { try { string text = Console.ReadLine(); if (text == "quit") break; Task.Run(async () => { if (text == "many") { text = new string('x', 8192); for (int i = 0; i < 1000000; i++) { await _client.SendAsync(Encoding.UTF8.GetBytes(text)); Console.WriteLine("Client [{0}] send text -> [{1}].", _client.LocalEndPoint, text); } } else if (text == "big") { text = new string('x', 1024 * 1024 * 100); await _client.SendAsync(Encoding.UTF8.GetBytes(text)); Console.WriteLine("Client [{0}] send text -> [{1}].", _client.LocalEndPoint, text); } else { await _client.SendAsync(Encoding.UTF8.GetBytes(text)); Console.WriteLine("Client [{0}] send text -> [{1}].", _client.LocalEndPoint, text); } }); } catch (Exception ex) { Logger.Get<Program>().Error(ex.Message, ex); } } _client.Close().Wait(); Console.WriteLine("TCP client has disconnected from server [{0}].", remoteEP); } catch (Exception ex) { Logger.Get<Program>().Error(ex.Message, ex); } Console.ReadKey(); }