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