如何使用 TCP/IP 套接字将数据发送到 VB.NET 中的多个 IP?
我有一个 IP 地址数组,我想向所有这些地址发送相同的数据。我可以只发送发送数据的循环代码,但我认为有更好的方法来做到这一点。
我听说过多播,它到底是什么?我认为这是我所需要的,但我该如何使用它。
I have an array of IP addresses, and I want to send the same data to all of them. I could just send the loop code that sends data but I think there's a better way of doing this.
I've heard of multicast, what exactly is it? I think it's what I need but how do i use it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,您可以为此使用多播。您的发送方只需向 224.xxx 到 239.xxx 范围内的任何地址发送 UDP 数据包。您的接收器侦听相同的地址,底层堆栈和网络结构确定如何将数据包从发送器发送到接收器。
请注意,此范围是细分的,因此某些地址比其他地址更适合您的应用程序。例如,您可以为仅在单个 LAN 上使用的程序选择 239.xxx。
另请注意,这仅适用于 UDP——没有多播 TCP 之类的东西——并且让它跨路由器工作可能很困难。让它在当前的互联网上工作尤其困难,因为大多数 ISP 不支持多播。
Yes, you can use multicast for this. Your sender just emits UDP packets to any address in the 224.x.x.x to 239.x.x.x range. Your receivers listen on the same address, and the underlying stack and network fabric figure out how to get the packets from sender to receiver.
Beware that this range is subdivided so that certain addresses will be more appropriate to your application than others. You might choose 239.x.x.x for a program that's only used on a single LAN, for instance.
Also beware that this only works with UDP -- there's no such thing as multicast TCP -- and that getting it to work across routers may be difficult. Getting it to work across the current Internet is especially difficult, since most ISPs don't support multicast.