According to the MSDN documentation Mango does not support UDP broadcast. According to this thread it is somehow possible. Does anybody have any experience with UDP on Phone 7? A code snippet in C# would be appreciated.
EDIT: We made some further investigations. The following code seems to work
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Broadcast, true);
byte[] data = Encoding.UTF8.GetBytes("test data");
SocketAsyncEventArgs a = new SocketAsyncEventArgs();
a.RemoteEndPoint = new IPEndPoint(IPAddress.Broadcast, 11000);
a.SetBuffer(data, 0, data.Length);
a.Completed += new EventHandler<SocketAsyncEventArgs>(delegate(object s, SocketAsyncEventArgs e)
{
Console.WriteLine(e.SocketError);
// here you can call socket.SendToAsync(sendEventArgs);
});
socket.ConnectToAsync(a);
It is essential to call ConnectToAsync before SendToAsync, otherwise you get an access denied exception. UDP seems to work somehow, at least in the emulator. The question is, will it work in real live and why the documentation says it doesn't?
For Windows Phone OS 7.1, TCP unicast, UDP unicast, and UDP multicast clients are supported (OS 7.1 means Windows Phone 7.5/Mango)
Here is link to documentation about the Socket Class: http://msdn.microsoft.com/en-us/library/attbb8f5(v=VS.95).aspx
Here is link to a blog with sample code: http://www.pitorque.de/MisterGoodcat/post/Windows-Phone-7-Mango-Sockets.aspx
And even more sample code under "09-DemoCode Networking" in http://borntolearn.mslearn.net/wpmango/m/mediagallery/default.aspx
Here is another message that might inspire you: How to broadcast a UDP packet on WP7 Mango?
There has been reported som OS firmware with bad UDP performance: http://connect.microsoft.com/VisualStudio/feedback/details/690198/poor-udp-performance-in-windows-phone-7-mango
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With