richTextBox1.Text = string.Empty;
//实例化UdpClient对象
UdpClient udpclient = new UdpClient(Convert.ToInt32(textBox2.Text));
//调用UdpClient对象的Connect建立默认远程主机
udpclient.Connect(textBox1.Text, Convert.ToInt32(textBox2.Text));
//定义一个字节数组,用来存放发送到远程主机的信息
Byte[] sendBytes = Encoding.Default.GetBytes(textBox3.Text);
//调用UdpClient对象的Send方法将Udp数据报发送到远程主机
udpclient.Send(sendBytes, sendBytes.Length);
//实例化IPEndPoint对象,用来显示响应主机的标识
IPEndPoint ipendpoint = new IPEndPoint(IPAddress.Any, 0);
//调用UdpClient对象的Receive方法获得从远程主机返回的Udp数据报
Byte[] receiveBytes = udpclient.Receive(ref ipendpoint);
2023-01-05 23:12:17
54KB
C#
网络技术
1