Name
MulticastSocket
Synopsis
This subclass of
DatagramSocket
can send and receive multicast UDP
packets. It extends DatagramSocket
by adding
joinGroup( )
and leaveGroup(
)
methods to join and leave multicast
groups. You do not have to join a group
to send a packet to a multicast address, but you must join the group
to receive packets sent to that address. Note that the use of a
MulticastSocket
is governed by a security manager.
Use setTimeToLive(
)
to set a time-to-live value
for any packets sent through a MulticastSocket
.
This constrains the number of network hops a packet can take and
controls the scope of a multicast. Use setInterface(
)
or
setNetworkInterface( )
to specify the
InetAddress
or the
NetworkInterface
that outgoing multicast packets
should use: this is useful for servers or other computers that have
more than one internet address or network interface.
setLoopbackMode(
)
specifies whether a multicast
packets sent through this socket should be send back to this socket
or not. This method should really be named
“setLoopbackModeDisabled( )”:
passing an argument of true
requests (but does not
require) that the system disable
loopback
packets.
Figure 12-12. java.net.MulticastSocket
public class MulticastSocket extends DatagramSocket { // Public Constructors public MulticastSocket( ) throws java.io.IOException; 1.4 public MulticastSocket(SocketAddress bindaddr) throws ...
Get Java in a Nutshell, 5th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.