Exemplo n.º 1
0
        private static async Task StartClientAsync(string host, int port)
        {
            var client = new TcpClient();

            try
            {
                await client.ConnectAsync(host, port);

                Statistics.IncrementClient();

                var runTask = RunClientAsync(client);
            }
            catch (SocketException ex)
            {
                Console.WriteLine($"Connect Error: SocketErrorCode = {ex.SocketErrorCode},  {ex}");
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Connect Error: {ex}");
            }
        }
Exemplo n.º 2
0
        private static async Task RunAsync()
        {
            var listener = new TcpListener(IPAddress.Any, 3400);

            listener.Start(655360);

            while (true)
            {
                try
                {
                    var client = await listener.AcceptTcpClientAsync();

                    var runClientTask = RunClientAsync(client);
                    Statistics.IncrementClient();
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"Accept Error: {ex}");
                    break;
                }
            }
            Console.WriteLine("RunAsync Finish");
        }