开发者

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.

  1. 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?

  2. 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 ..

  3. 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!!


  1. According to documentation "For Windows Phone OS 7.1, TCP unicast, UDP unicast, and UDP multicast clients are supported." (I used your link)
  2. My understanding is that you can receive only from an IP you initiated a communication with, that's for security purposes..
  3. You are mixing c# code with Silverlight code, WP7 only supports Silverlight.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜