private void Button_Click(object sender, RoutedEventArgs e) { try { epLocal = new IPEndPoint(IPAddress.Parse(MyIP), Convert.ToInt32(port)); sck.Bind(epLocal); epRemote = new IPEndPoint(IPAddress.Parse(FriendIP), Convert.ToInt32(friendPort)); sck.Connect(epRemote); byte[] buffer = new byte[1500]; sck.BeginReceiveFrom(buffer, 0, buffer.Length, SocketFlags.None, ref epRemote, new AsyncCallback(MessageCallBack), buffer); MessageBox.Show("Connected"); UserMesageBox.Focus(); Createchat.IsEnabled = false; send.IsEnabled = true; } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
private void Send_Click(object sender, RoutedEventArgs e) { try { System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding(); byte[] msg = new byte[1500]; msg = enc.GetBytes(UserMesageBox.Text); The_chat.Items.Add("You : " + UserMesageBox.Text); UserMesageBox.Clear(); UserMesageBox.Focus(); } catch (Exception s) { MessageBox.Show(s.ToString()); } }