Пример #1
0
        /// <summary>
        /// Receive message from server
        /// </summary>
        public void ReceiveMessage()
        {
            //receive the server message
            _strReceiver = new StreamReader(_manageConnection.TcpClient.GetStream());

            //receive response
            string[] response = _strReceiver.ReadLine().Split(Constants.ESCAPE_SPLIT_MSG);

            if (response.Length >= 2)
            {
                //print error message
                ChatLayout.PrintSimpleMessage(string.Format(MessageConstants.ADMIN_DEFAULT_MSG, response[1]));

                //reinitialize
                _manageClient.InitializeChat();
            }
            else
            {
                //print the line of receiver
                ChatLayout.PrintSimpleMessage(response[0]);

                //is connected
                while (_manageConnection.TcpClient.Connected)
                {
                    // exibe mensagems no Textbox
                    ChatLayout.PrintSimpleMessage(_strReceiver.ReadLine());
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Start the client chat
        /// </summary>
        public void InitializeChat()
        {
            //nickname
            ChatLayout.PrintSimpleMessage(MessageConstants.USERNAME_MSG);

            //set callback
            _exchangeServer.SendUserToServerCallback = InitializeChat;

            //send nickname to server
            _exchangeServer.SendUser(Console.ReadLine());

            //try connect to server
            if (_manageConnection.TcpClient.Connected)
            {
                //menu
                ChatLayout.PrintMenuChat();

                //set thread to receive messages
                _trhReceiveMessages = new Thread(new ThreadStart(_exchangeServer.ReceiveMessage));
                _trhReceiveMessages.Start();

                //filter messages and send to server
                while (_manageConnection.TcpClient.Connected)
                {
                    _exchangeServer.FilterMessage(Console.ReadLine());
                }
            }
            else
            {
                Console.ReadLine();
            }
        }
Пример #3
0
 /// <summary>
 /// Create a TCP Connection
 /// </summary>
 public void Connect()
 {
     try
     {
         //initialize the tcp connection
         TcpClient = new TcpClient();
         TcpClient.Connect(Network.GetLocalIPAddress(), Constants.LAN_PORT);
     }
     catch (Exception ex)
     {
         ChatLayout.PrintSimpleMessage(MessageConstants.NOT_CONNECTED_SERVER_ERR + "\n Exception: " + ex.Message);
     }
 }
Пример #4
0
 /// <summary>
 /// Show menu options
 /// </summary>
 public void ShowMenuChat()
 {
     ChatLayout.PrintMenuChat();
 }