使用UdpClient怎么总是接收时出问题???
代码:
UdpClient UdpA=new UdpClient();
byte[] sendBytes=Encoding.ASCII.GetBytes("hello");
richTextBox1.AppendText("->A "+DateTime.Now+":\r\n"+textBox1.Text+"\r\n");
UdpA.Connect("127.0.0.1",5);
UdpA.Send(sendBytes,sendBytes.Length);
UdpClient UdpB=new UdpClient(5);
IPEndPoint RemoteIpEndPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 5);
while(true)
{
byte[] receiveBytes=UdpB.Receive(ref RemoteIpEndPoint);
string receiveMessage=Encoding.ASCII.GetString(receiveBytes);
richTextBox1.AppendText("<-A "+DateTime.Now+":\r\n"+receiveMessage+"\r\n");
}
UdpA.Close();
UdpB.Close();