日期:2014-05-18 浏览次数:20767 次
public void ReceiveMessage()
{
//在本机指定的端口接收
IPEndPoint remoteIpEndIPoint = new IPEndPoint(IPAddress.Any,1000);
udpReceive = new UdpClient(remoteIpEndIPoint);
IPEndPoint iep = new IPEndPoint(IPAddress.Any, 0);
//接收从远程主机发送过来的信息
while (true)
{
//ref表示引用类型的 IPPoint实例接收消息
byte[] receiveBytes = udpReceive.Receive(ref iep);
for (int i = 0; i < receiveBytes.Length; i++)
{
RetStr += String.Format("{0:X2} ", receiveBytes[i]);
}
MessageBox.Show(RetStr);
}
}