我认为这真的很奇怪。尝试使用UdpClient同步接收广播消息,但尽管广播已完成,但它不会返回。只有在随后的广播中才收到消息。我认为框架内某处有一个错误?
clientListener.BeginReceive(new AsyncCallback(RxBcastCallback), clientListener);
//this is passed as AsyncCall.AsyncState in the callback
.....
UdpClient udpListener = (UdpClient)AsyncCall.AsyncState;
IPEndPoint remoteEndPt = new IPEndPoint(IPAddress.Any, 0);
byte[] inBuffer = udpListener.Receive(ref remoteEndPt);
//does not return until subsequent broadcast
感谢, 肯尼
答案 0 :(得分:1)
你的回调终点应该是:
UdpClient udpListener = (UdpClient)AsyncCall.AsyncState;
IPEndPoint e = (IPEndPoint)((UdpState)(AsyncCall.AsyncState)).e;
byte[] inBuffer= udpListener.EndReceive(AsyncCall, ref e);