首先尝试使用msdn方式从localhost的任何源接收数据,然后从其他主机名接收数据:
https://msdn.microsoft.com/en-us/library/system.net.sockets.udpclient(v=vs.110).aspx
// This constructor arbitrarily assigns the local port number.
UdpClient udpClient = new UdpClient(17000);
udpClient.Connect("127.0.0.1", 17000);
// Sends a message to the host to which you have connected.
Byte[] sendBytes = Encoding.ASCII.GetBytes("Is anybody there?");
udpClient.Send(sendBytes, sendBytes.Length);
//// Sends a message to a different host using optional hostname and port parameters.
//UdpClient udpClientB = new UdpClient();
//udpClientB.Send(sendBytes, sendBytes.Length, "AlternateHostMachineName", 17000);
//IPEndPoint object will allow us to read datagrams sent from any source.
IPEndPoint RemoteIpEndPoint = new IPEndPoint(IPAddress.Any, 0);
// Blocks until a message returns on this socket from a remote host.
Byte[] receiveBytes = udpClient.Receive(ref RemoteIpEndPoint);
string returnData = Encoding.ASCII.GetString(receiveBytes);