简体   繁体   中英

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

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?

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 ;-)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM