UdpClient 接收直到第二次广播才返回

发布于 2024-10-15 09:35:33 字数 528 浏览 3 评论 0原文

我觉得这真的很奇怪。尝试使用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

谢谢, 肯尼

I think this is really weird. Tried to use UdpClient to synchronously receive broadcast msg, but it does not return although the broadcast has completed. Only on subsequent broadcast did I get the message. I think there's a bug somewhere within the framework?

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

thanks,
Kenny

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

箜明 2024-10-22 09:35:33

您的回调端点可能应该是:

UdpClient udpListener = (UdpClient)AsyncCall.AsyncState;
IPEndPoint e = (IPEndPoint)((UdpState)(AsyncCall.AsyncState)).e;
byte[] inBuffer= udpListener.EndReceive(AsyncCall, ref e);

Your callback endpoint should probably be:

UdpClient udpListener = (UdpClient)AsyncCall.AsyncState;
IPEndPoint e = (IPEndPoint)((UdpState)(AsyncCall.AsyncState)).e;
byte[] inBuffer= udpListener.EndReceive(AsyncCall, ref e);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文