Windows Phone - Udp

元气小坏坏 提交于 2019-12-11 11:44:15

问题


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 = new 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:


  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.


来源:https://stackoverflow.com/questions/7501495/windows-phone-udp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!