Issues with async receiving UDP Unicast packets in Windows Phone 7

后端 未结 4 1338
你的背包
你的背包 2020-12-19 04:24

I\'m trying to get my Windows Phone 7 Mango app to listen to incoming UDP packets but having a heck of a time. I have the new Beta 2 refresh of the Windows Phone 7.1 SDK and

相关标签:
4条回答
  • 2020-12-19 04:51

    You need to call ReceiveFormAsync() from the Completed event of SendTAsync()..Otherwise, you will get this exception..

    0 讨论(0)
  • 2020-12-19 04:54

    Have you seen the sample at http://msdn.microsoft.com/en-us/library/hh202864(v=VS.92).aspx#Y4537?

    Given that TCP sockets are client-only in Mango, I wonder is UDP sockets might only work after something has been sent? I would suggest trying that. If that doesn't work, could you post your entire project on dropbox or the like, and I'll look at it.

    Thanks, --randy

    0 讨论(0)
  • 2020-12-19 04:59

    I had this same problem, but here is the solution that I came up with. As wilbur4321 said, you have to send something to the socket first. Also, not only do you need to just call SendToAsync and forget about it, you must wait for it (max of 1 second seems to work for me).

    I do not know why you are required to do this, but sending something (I just send 1 byte: 0xFF) seems to do the trick.

    0 讨论(0)
  • 2020-12-19 05:12

    I found that a strange thing in that "Win7 UDP server" sample that is the server-side UDP socket doesn't "Bind"

    in my experiment, call "ReceiveFromAsync" on a socket which doesn't bind, "invalid argument" exception is throw. After binding before "ReceiveFromAsync", at least "ReceiveFromAsync" won't throw "invalid argument" exception.

    My codes is similar to yours, but there is still some problems. it seems that, I call "ReceiveFromAsync" once, but the OS fire the event callbacks twice, which cause very serious race condition.

    There is so few sample, documents about "UDP + SocketAsyncEventArgs". Maybe I have to revert back to using "BeginReceiveFrom".

    0 讨论(0)
提交回复
热议问题