有没有人尝试在Windows Phone 7.1(RC)上使用Udp Unicast?我有几个问题,我想问你们。
根据文档http://msdn.microsoft.com/en-us/library/system.net.sockets.socket(v=VS.95).aspx,唯一支持的ProtocolType是TCP协议。这是否意味着Udp Unicast不完全支持?
我发现我们只能在SendToAsync的Completed事件中调用ReceiveFromAsync。否则,它将抛出“提供了无效参数”异常。它为什么这样工作?其他也有同样的问题Issues with async receiving UDP Unicast packets in Windows Phone 7 ..
我使用MSDN示例和其他一些C#Udp客户端进行了测试。我发现SendToAsync方法工作正常。但是ReceiveFromAsync不起作用。有谁知道如何解决它?
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);
}
谢谢你们!
答案 0 :(得分:1)