I hope you have solved the problem by now, but if you haven't yet here is the solution.
private static int nPort = 12345;
private static EndPoint EndPointRemote;
private static int nBufSize = 1024;
public void Start()
{
//
// Wait until we have an IP address.
//
while (IPAddress.GetDefaultLocalAddress() == IPAddress.Any)
{
Thread.Sleep(10);
}
Debug.Print("IP Address: " + IPAddress.GetDefaultLocalAddress());
EndPointRemote = new IPEndPoint(IPAddress.Any, nPort);
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
socket.Bind(EndPointRemote);
int bytesRead;
byte[] buffer = new byte[nBufSize + 1];
while (true)
{
if( (bytesRead = socket.ReceiveFrom(buffer, nBufSize, SocketFlags.None, ref EndPointRemote)) > 0 )
{
Debug.Print("Message received from " + EndPointRemote.ToString() + ": " + new string(System.Text.Encoding.UTF8.GetChars(buffer, 0, bytesRead)));
}
Thread.Sleep(0);
}
}
Let me know if this work for you.
Bizhan.