Windows Phone - Udp
Does anyone try using Udp Unicast on Windows Phone 7.1 (RC)? I have a few questions that I like to ask you guys.
According to the document http://msdn.microsoft.com/en-us/library/system.net.sockets.socket(v=VS.95).aspx, the only supported ProtocolType is the TCP protocol. Does it mean Udp Unicast is not fully supported?
I found that we can only call ReceiveFromAsync at the Completed event of SendToAsync. Otherwise, it will throws "An invalid argument was supplied" exception. Why does it work like that? Other also have the same issue Issues with async receiving UDP Unicast packets in Windows Phone 7 ..
I tested with MSDN sample and a few other C# Udp clients as well. I found that SendToAsync method is working fine. But ReceiveFromAsync is not working. Does anyone has any idea how to fix it?
private void OnRecieve() { var receiveArgs = new SocketAsyncEventArgs(); receiveArgs.RemoteEndPoint = n开发者_如何学Pythonew IPEndPoint(IPAddress.Any, PORT); receiveArgs.SetBuffer(new Byte[1024], 0, 1024); var strBdr = new StringBuilder(); receiveArgs.Completed += (__, result) => { var package = Encoding.UTF8.GetString(result.Buffer, 0, result.BytesTransferred); if (!string.IsNullOrEmpty(package)) { this.RaiseReceived(package); } socket.ReceiveFromAsync(receiveArgs); }; socket.ReceiveFromAsync(receiveArgs); }
Thanks guys!!
- According to documentation "For Windows Phone OS 7.1, TCP unicast, UDP unicast, and UDP multicast clients are supported." (I used your link)
- My understanding is that you can receive only from an IP you initiated a communication with, that's for security purposes..
- You are mixing c# code with Silverlight code, WP7 only supports Silverlight.
精彩评论