Java Reference
In-Depth Information
including 1) allowing specification of the datagram TTL, and 2) allowing the interface through
which datagrams are sent to the group to be specified/changed (an interface is identified by its
Internet address). A multicast receiver, on the other hand,
must
use a
MulticastSocket
because
it needs the ability to join a group.
MulticastSocket
is a subclass of
DatagramSocket
, so it provides all of the
DatagramSocket
methods. We only present methods specific to or adapted for
MulticastSocket
.
MulticastSocket
Constructors
MulticastSocket
()
MulticastSocket
(
int
localPort
)
Constructs a datagram socket that can perform some additional multicast operations.
The second form of the constructor specifies the local port. If the local port is not
specified, the socket is bound to any available local port.
localPort
Local port. A localPort of 0 allows the constructor to pick
any available port.
Operators
void
joinGroup
(
InetAddress
groupAddress
)
void
leaveGroup
(
InetAddress
groupAddress
)
Join/leave a multicast group. A socket may be a member of multiple groups simulta-
neously. Joining a group of which this socket is already a member or leaving a group
of which this socket is not a member may generate an exception.
groupAddress
Multicast address identifying group
void
send
(
DatagramPacket
packet
,
byte
TTL
)
Send a datagram from this socket with the specified TTL.
packet
Packet to transmit. Either the packet must specify a
destination address or the UDP socket must have a specified
remote address and port (see
connect()
).
TTL
Time to live for this packet
Accessors
InetAddress
getInterface
()
void
setInterface
(
InetAddress
interface
)
Returns/sets the interface to use for multicast operations on this socket. This is
primarily used on hosts with multiple interfaces. Join/leave requests and datagrams
Search WWH ::
Custom Search