Why DatagramSocket.joinGroup() method takes a SocketAddress if the port does not matter for a multicast group?

柔情痞子 提交于 2019-12-22 05:48:13

问题


I am just curious. Is that an API mistake? When you join a multicast group you do NOT use the port, just the multicast address (IP) which is the multicast group, right?

Is that an annoyance of is there ever the case when the PORT will be used?


回答1:


The question would be better reformulated as 'why does DatagramSocket.joinGroup() take a SocketAddress parameter, which can contain a port number?'

The port number in the SocketAddress is ignored. Multicast is defined entirely in terms of IP addresses. I think the reason for using SocketAddress is that it can imply an unresolved address, where InetAddress implies a resolved address, and you can't resolve multicast addresses, but don't quote me ;-)



来源:https://stackoverflow.com/questions/9468991/why-datagramsocket-joingroup-method-takes-a-socketaddress-if-the-port-does-not

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