Exemplo n.º 1
0
 private void SendButton_Click(object sender, EventArgs e)
 {
     if (connected == true)
     {
         if (currentUser == null)
         {
             currentUser = UserTextBox.Text;
             sw.WriteLine(currentUser);
         }
         else
         {
             try
             {
                 string  message    = UserTextBox.Text;
                 Message newMessage = new Message(currentUser, message);
                 messageList.Add(newMessage);
                 sw.WriteLine(currentUser + ": " + message);
             }
             catch
             {
                 ChatRichTextBox.AppendText("Failed to deliver message \n");
             }
         }
         sw.Flush();
         UserTextBox.Clear();
     }
     else
     {
         MessageBox.Show("Not connected to server.");
     }
 }
Exemplo n.º 2
0
        public void receive()
        {
            while (true)
            {
                try
                {
                    string response = sr.ReadLine();
                    Console.WriteLine(response);

                    string userName = response.Substring(0, response.IndexOf(':'));
                    string message  = response.Substring(response.IndexOf(':') + 1);
                    //Console.WriteLine("userName: "******" ,message: " + message);
                    Message newMessage = new Message(userName, message);
                    messageList.Add(newMessage);
                    ChatRichTextBox.AppendText(response + " \n");
                }
                catch
                {
                }
            }
        }