Reputation: 4994
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 = 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!!
Upvotes: 1
Views: 937
Reputation: 667
Upvotes: 1