Beispiel #1
0
        private static async Task SendRequest(string server,
                                              int port)
        {
            try
            {
                TcpClient client = new TcpClient();
                await client.ConnectAsync(IPAddress.Parse(server), port); // Connect

                using (NetworkStream networkStream = client.GetStream())
                {
                    string line;
                    while ((line = Console.ReadLine()) != null)
                    {
                        await CommandResolve.ProcessInput(networkStream, line);
                    }
                }
                client.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Beispiel #2
0
        private async Task Process(TcpClient tcpClient)
        {
            string clientEndPoint =
                tcpClient.Client.RemoteEndPoint.ToString();

            Console.WriteLine("Received connection request from "
                              + clientEndPoint);
            try
            {
                using (NetworkStream networkStream = tcpClient.GetStream())
                {
                    await CommandResolve.ProcessStream(networkStream);
                }
                tcpClient.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                if (tcpClient.Connected)
                {
                    tcpClient.Close();
                }
            }
        }
Beispiel #3
0
 public CommandDispatcher(IEnumerable <CommandHandlerModule> commandHandlerModules)
 {
     _resolver = CommandResolve.WhenEqualToHandlerMessageType(commandHandlerModules);
 }