MulticastSocket constructors and binding to port or SocketAddress

不打扰是莪最后的温柔 提交于 2019-12-04 05:07:45

If you don't specify a local IP address when you create or bind it, it binds to 0.0.0.0, which means 'accept input via any NIC'. This is normally what you want.

It is possible to bind to a specific IP address, which implicitly means the corresponding NIC, but some systems such as Linux seem to expect multicast sockets, if bound, to be bound to the multicast group itself. This doesn't make any sense to me: what if you want to join another group?

I think the best and most portable idea is to listen at 0.0.0.0 and join via either a specific NIC, or via all NICs, one at a time. The latter is necessary in multi-homed hosts unless you are confident that the default route to the multicast group is the one you want the join request sent out on, because that's what happens if you don't specify a join interface.

I think that you are missing the point with your address binding:

http://download.java.net/jdk7/archive/b123/docs/api/java/net/MulticastSocket.html
A multicast group is specified by a class D IP address and by a standard UDP port number. Class D IP addresses are in the range 224.0.0.0 to 239.255.255.255, inclusive. The address 224.0.0.0 is reserved and should not be used.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!