接收远程主机作为广播消息发送的数据报

发布于 2024-07-16 13:46:01 字数 194 浏览 3 评论 0原文

我需要接收由连接在同一局域网上的远程主机作为广播消息发送的数据报。

我正在使用 UDPClient 但不知道要使用哪种方法。有一个方法 UDPClient.Receive 但需要一个特定的 IPEndPoint 作为参数,这显然是不需要的,因为它是我需要接收的广播消息,因此发送者不是重要的。 如果可能,请向我提供接收广播消息的代码。 谢谢。

I need to receive datagrams that are sent as a broadcast message by remote host connected on the same lan.

I am using UDPClient but have no idea which method to use.There is a method UDPClient.Receive but that requires as parameter a specific IPEndPoint which is obviously not wanted since it is a broadcast message that I need to receive and hence the sender is not important.
Please if possible provide me with the code to receive a broadcast message.
Thanks.

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

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

发布评论

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

评论(1

执手闯天涯 2024-07-23 13:46:01

将 IPEndPoint 设置为使用 ANY 地址:

int port = ...your port goes here...
var endPoint = new IPEndPoint( IPAddress.Any, port );

然后像平常一样使用 UDPClient.Receive。

Set up the IPEndPoint to use the ANY address:

int port = ...your port goes here...
var endPoint = new IPEndPoint( IPAddress.Any, port );

Then use UDPClient.Receive as you normally would.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文