Exemplo n.º 1
0
 /*
  * Method :		UpdateChatArea()
  * Parameter:      Object obj: The received message
  * Description:    This is a a callback funtion to update the listbox
  * Return value:	No
  */
 private void UpdateChatArea(Object obj)
 {
     try
     {
         string client2 = To.Text;
         string msg     = (string)obj;
         // Add the message to the listbox and auto scroll tp last one
         History.Items.Add("\t\t[ " + DateTime.Now.ToString("HH:mm") + " ]  " + msg);
         History.ScrollIntoView(History.Items[History.Items.Count - 1]);
     }
     catch (Exception ex)
     {
         Error.Content = ex;
     }
 }
Exemplo n.º 2
0
        /*
         * Method :		SendCrypt_Click()
         * Description:    When the Connection Button Clickedit sent the message with encrepted.
         * Return value:	No
         */

        private void SendCrypt_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                // Check the connection status. If the server is connected
                // Read the text form textbox and send it to the server
                if (connect)
                {
                    if (Chat.Text != "")
                    {
                        StreamWriter output      = new StreamWriter(clientList[0]);
                        StreamWriter cryptOutput = new StreamWriter(clientList[0]);
                        string       x           = Chat.Text;
                        History.Items.Add("[ " + DateTime.Now.ToString("HH:mm") + " ] You:  " + Chat.Text);
                        History.ScrollIntoView(History.Items[History.Items.Count - 1]);

                        string outp = Chat.Text;
                        output.WriteLine(outp);
                        output.Flush();
                        //Applying the BlowFish encryption to the message
                        string encrypted = blowFish.Encrypt_CBC(outp);

                        cryptOutput.WriteLine(encrypted);
                        //output.WriteLine(outp);
                        cryptOutput.Flush();
                        Chat.Clear();
                    }
                    else
                    {
                        Error.Content = ">>!!!Message can not be blank!!!<<";
                    }
                }
                // Otherwiser notify the user Sever is not connected
                else
                {
                    Error.Content = ">>!!!You are not connected to the Server!!!<<";
                }
            }
            catch (Exception ex)
            {
                Error.Content = ex;
            }
        }