Exemplo n.º 1
0
        private void HandleClientRequest(object obj)
        {
            Console.WriteLine("Client connected!");
            var          tcpClient    = (TcpClient)obj;
            var          clientStream = tcpClient.GetStream();
            var          reader       = new StreamReader(clientStream);
            var          writer       = new StreamWriter(clientStream);
            LoggedClient loggedClient = null;

            try
            {
                var registerMessage  = GetRegisterMessage(reader);
                var AESKey           = AESWrapper.GetRandomBytes();
                var registerResponse = GetRegisterResponse(registerMessage, AESKey);
                writer.WriteLine(registerResponse);
                writer.Flush();
                Console.WriteLine("Client registered!");
                loggedClient = AuthorizeUser(tcpClient, AESKey);
                while (running)
                {
                    Console.WriteLine("While true...");


                    var input = reader.ReadLine();
                    if (input == null)
                    {
                        throw new ArgumentNullException("Null input");
                    }
                    loggedClient.HandleIncomingRequests(input);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }
            Console.WriteLine("logging out...");
            LogOutClient(loggedClient);
        }