private void buttSend_Click(object sender, EventArgs e) { try { System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding(); byte[] msg = new byte[1500]; msg = enc.GetBytes(TextMessBoxC1.Text); //send the message to other client sck.Send(msg); items.Add(" You: " + TextMessBoxC1.Text); listBoxClient1.DataSource = null; listBoxClient1.DataSource = items; //listBoxClient1.Items.Add("You: " + TextMessBoxC1.Text); TextMessBoxC1.Clear(); } catch (Exception exp) { textBoxEMessage.Text = "You need to connect first"; MessageBox.Show(exp.ToString()); textBoxEMessage.Clear(); } }
private void buttConnect_Click(object sender, EventArgs e) { try { //binding socket epLocal = new IPEndPoint(IPAddress.Parse(textBoxHostIP.Text), Convert.ToInt32(textBoxHPort.Text)); sck.Bind(epLocal); //connection with remote host epRemote = new IPEndPoint(IPAddress.Parse(textBoxDesIP.Text), Convert.ToInt32(textBoxDesPort.Text)); sck.Connect(epRemote); // listening byte[] buffer = new byte[1500]; sck.BeginReceiveFrom(buffer, 0, buffer.Length, SocketFlags.None, ref epRemote, new AsyncCallback(MessageCallBack), buffer); textBoxEMessage.Text = "Your friend is now connected"; //buttConnect.Text = "Connected"; buttConnect.Enabled = false; buttSend.Enabled = true; TextMessBoxC1.Focus(); } catch (Exception exp) { MessageBox.Show(exp.ToString()); } }
private void buttCrypSend_Click(object sender, EventArgs e) { // EXAMPLE //string plainText = "The quick brown fox jumped over the lazy dog."; //string cipherText = blowFish.Encrypt_CBC(plainText); //MessageBox.Show(cipherText); //plainText = blowFish.Decrypt_CBC(cipherText); //MessageBox.Show(plainText); //System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding(); ////byte[] msg = new byte[1500]; //msg = enc.GetBytes(TextMessBoxC1.Text); ////send the message to other client //sck.Send(msg); //items.Add(" You: " + TextMessBoxC1.Text); //listBoxClient1.DataSource = null; //listBoxClient1.DataSource = items; try { System.Text.ASCIIEncoding encode = new System.Text.ASCIIEncoding(); byte[] msg = new byte[1500]; //msg = encode.GetBytes(TextMessBoxC1.Text); string hmsg = TextMessBoxC1.Text; string encrypted = blowFish.Encrypt_CBC(hmsg); msg = encode.GetBytes(encrypted); //send the message to other client sck.Send(msg); items.Add(" You: " + TextMessBoxC1.Text); listBoxClient1.DataSource = null; listBoxClient1.DataSource = items; //listBoxClient1.Items.Add("You: " + TextMessBoxC1.Text); TextMessBoxC1.Clear(); } catch (Exception exp) { textBoxEMessage.Text = "You need to connect first"; MessageBox.Show(exp.ToString()); textBoxEMessage.Clear(); } }