A few questions/comments about java.net.MulticastSocket

Alan Bateman Alan.Bateman at oracle.com
Tue Jan 19 18:55:33 UTC 2021


On 19/01/2021 18:36, Vitaly Davidovich wrote:
> Hi all,
>
> A few colleagues and I were trying to make sense of the 
> joinGroup(SocketAddress, NetworkInterface) 
> <https://github.com/openjdk/jdk/blob/05a764f4ffb8030d6b768f2d362c388e5aabd92d/src/java.base/share/classes/java/net/MulticastSocket.java#L382> 
> method.  In particular:
>
>   * Why does this take a SocketAddress and then ignores the port in
>     the implementation? Any reason it doesn't take InetAddress, which
>     would make it clear the port is unnecessary? The deprecated
>     overload of joinGroup takes an InetAddress (and is deprecated
>     because it didn't allow specifying the network interface).
>
That was an API mistake in Java 1.4. When DatagramChannel was updated to 
support joining multicast groups (in Java 7) it was able to get the 
parameters right.


>   * The MulticastSocket class javadoc still talks
>     <https://github.com/openjdk/jdk/blob/05a764f4ffb8030d6b768f2d362c388e5aabd92d/src/java.base/share/classes/java/net/MulticastSocket.java#L45>
>     about using joinGroup(InetAddress) as the way to join a group. 
>     Should probably be updated to mention the non-deprecated overload.
>   * Also in the class javadoc, there's a "stray" port variable
>     <https://github.com/openjdk/jdk/blob/05a764f4ffb8030d6b768f2d362c388e5aabd92d/src/java.base/share/classes/java/net/MulticastSocket.java#L52>
>     that's not defined anywhere in the example.  Since the port is
>     ignored by the joinGroup method, what is this port supposed to
>     represent?
>
Yes, the javadoc needs some TLC.

-Alan

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/net-dev/attachments/20210119/e0d38ad5/attachment.htm>


More information about the net-dev mailing list