public class MulticastSocket extends DatagramSocket
DatagramSocket| Constructor and Description |
|---|
MulticastSocket()
Constructs a multicast socket, bound to any available port on the
local host.
|
MulticastSocket(int port)
Constructs a multicast socket, bound to the specified
port on the
local host. |
MulticastSocket(SocketAddress localAddress)
Constructs a
MulticastSocket bound to the address and port specified by
localAddress, or an unbound MulticastSocket if localAddress == null. |
| Modifier and Type | Method and Description |
|---|---|
InetAddress |
getInterface()
Returns an address of the outgoing network interface used by this socket.
|
boolean |
getLoopbackMode()
Returns true if multicast loopback is disabled.
|
NetworkInterface |
getNetworkInterface()
Returns the outgoing network interface used by this socket.
|
int |
getTimeToLive()
Returns the time-to-live (TTL) for multicast packets sent on this socket.
|
byte |
getTTL()
Deprecated.
Use
getTimeToLive() instead. |
void |
joinGroup(InetAddress groupAddr)
Adds this socket to the specified multicast group.
|
void |
joinGroup(SocketAddress groupAddress,
NetworkInterface netInterface)
Adds this socket to the specified multicast group.
|
void |
leaveGroup(InetAddress groupAddr)
Removes this socket from the specified multicast group.
|
void |
leaveGroup(SocketAddress groupAddress,
NetworkInterface netInterface)
Removes this socket from the specified multicast group.
|
void |
send(DatagramPacket packet,
byte ttl)
Deprecated.
Use
setTimeToLive(int) instead. |
void |
setInterface(InetAddress address)
Sets the outgoing network interface used by this socket.
|
void |
setLoopbackMode(boolean disable)
Disables multicast loopback if
disable == true. |
void |
setNetworkInterface(NetworkInterface networkInterface)
Sets the outgoing network interface used by this socket to the given
networkInterface. |
void |
setTimeToLive(int ttl)
Sets the time-to-live (TTL) for multicast packets sent on this socket.
|
void |
setTTL(byte ttl)
Deprecated.
Use
setTimeToLive(int) instead. |
bind, close, connect, connect, disconnect, getBroadcast, getChannel, getFileDescriptor$, getInetAddress, getLocalAddress, getLocalPort, getLocalSocketAddress, getPort, getReceiveBufferSize, getRemoteSocketAddress, getReuseAddress, getReusePort, getSendBufferSize, getSoTimeout, getTrafficClass, isBound, isClosed, isConnected, onBind, onClose, onConnect, onDisconnect, receive, send, setBroadcast, setDatagramSocketImplFactory, setReceiveBufferSize, setReuseAddress, setReusePort, setSendBufferSize, setSoTimeout, setTrafficClasspublic MulticastSocket()
throws IOException
IOException - if an error occurs.public MulticastSocket(int port)
throws IOException
port on the
local host.IOException - if an error occurs.public MulticastSocket(SocketAddress localAddress) throws IOException
MulticastSocket bound to the address and port specified by
localAddress, or an unbound MulticastSocket if localAddress == null.IllegalArgumentException - if localAddress is not supported (because it's not
an InetSocketAddress, say).IOException - if an error occurs.public InetAddress getInterface() throws SocketException
getNetworkInterface() instead.SocketException - if an error occurs.public NetworkInterface getNetworkInterface() throws SocketException
SocketException - if an error occurs.public int getTimeToLive()
throws IOException
IOException - if an error occurs.@Deprecated public byte getTTL() throws IOException
getTimeToLive() instead.IOException - if an error occurs.public void joinGroup(InetAddress groupAddr) throws IOException
groupAddr - the multicast group to be joined.IOException - if an error occurs.public void joinGroup(SocketAddress groupAddress, NetworkInterface netInterface) throws IOException
groupAddress - the multicast group to be joined.netInterface - the network interface on which the datagram packets will be
received.IOException - if the specified address is not a multicast address.IllegalArgumentException - if no multicast group is specified.public void leaveGroup(InetAddress groupAddr) throws IOException
groupAddr - the multicast group to be left.NullPointerException - if groupAddr is null.IOException - if the specified group address is not a multicast address.public void leaveGroup(SocketAddress groupAddress, NetworkInterface netInterface) throws IOException
groupAddress - the multicast group to be left.netInterface - the network interface on which the addresses should be
dropped.IOException - if the specified group address is not a multicast address.IllegalArgumentException - if groupAddress is null.@Deprecated public void send(DatagramPacket packet, byte ttl) throws IOException
setTimeToLive(int) instead.packet on this socket, using the given ttl. This method is
deprecated because it modifies the TTL socket option for this socket twice on each call.IOException - if an error occurs.public void setInterface(InetAddress address) throws SocketException
address. To avoid inherent unpredictability,
new code should use getNetworkInterface() instead.SocketException - if an error occurs.public void setNetworkInterface(NetworkInterface networkInterface) throws SocketException
networkInterface.setNetworkInterface in class DatagramSocketSocketException - if an error occurs.public void setTimeToLive(int ttl)
throws IOException
IOException - if an error occurs.@Deprecated public void setTTL(byte ttl) throws IOException
setTimeToLive(int) instead.IOException - if an error occurs.public boolean getLoopbackMode()
throws SocketException
SocketOptions.IP_MULTICAST_LOOP, and note that the sense of this is the
opposite of the underlying Unix IP_MULTICAST_LOOP.SocketException - if an error occurs.public void setLoopbackMode(boolean disable)
throws SocketException
disable == true.
See SocketOptions.IP_MULTICAST_LOOP, and note that the sense of this is the
opposite of the underlying Unix IP_MULTICAST_LOOP: true means disabled, false
means enabled.SocketException - if an error occurs.