java.lang.Object java.net.DatagramSocket java.net.MulticastSocketpublic class MulticastSocket extends DatagramSocket MulticastSocket()MulticastSocket(int port)MulticastSocket(SocketAddress address) InetAddress getInterface() boolean getLoopbackMode() NetworkInterface getNetworkInterface() byte getTTL() int getTimeToLive() void joinGroup(InetAddress mcastaddr) void joinGroup(SocketAddress mcastaddr, NetworkInterface netIf) void leaveGroup(InetAddress mcastaddr) void leaveGroup(SocketAddress mcastaddr, NetworkInterface netIf) void send(DatagramPacket packet, byte ttl) void setInterface(InetAddress addr) void setLoopbackMode(boolean disable) void setNetworkInterface(NetworkInterface netIf) void setTTL(byte ttl)setTimeToLive void setTimeToLive(int ttl)bind, close, connect, connect, disconnect, getBroadcast, getChannel, getInetAddress, getLocalAddress, getLocalPort, getLocalSocketAddress, getPort, getReceiveBufferSize, getRemoteSocketAddress, getReuseAddress, getSendBufferSize, getSoTimeout, getTrafficClass, isBound, isClosed, isConnected, receive, send, setBroadcast, setDatagramSocketImplFactory, setReceiveBufferSize, setReuseAddress, setSendBufferSize, setSoTimeout, setTrafficClass public MulticastSocket() throws IOException
Create a MulticastSocket that this not bound to any address
- Throws:
IOException- If an error occursSecurityException- If a security manager exists and its checkListen method doesn't allow the operation
public MulticastSocket(int port) throws IOException
Create a multicast socket bound to the specified port
- Parameters:
port- The port to bind to
- Throws:
IOException- If an error occursSecurityException- If a security manager exists and its checkListen method doesn't allow the operation
public MulticastSocket(SocketAddress address) throws IOException
Create a multicast socket bound to the specified SocketAddress.
- Parameters:
address- The SocketAddress the multicast socket will be bound to
- Throws:
IOException- If an error occursSecurityException- If a security manager exists and its checkListen method doesn't allow the operation
- Since:
- 1.4
public InetAddress getInterface() throws SocketException
Returns the interface being used for multicast packets
- Returns:
- The multicast interface
- Throws:
SocketException- If an error occurs
public boolean getLoopbackMode() throws SocketException
Checks if local loopback mode is enabled
- Returns:
- true if loopback mode is enabled, false otherwise
- Throws:
SocketException- If an error occurs
- Since:
- 1.4
public NetworkInterface getNetworkInterface() throws SocketException
Gets the local network interface which is used to send multicast messages
- Returns:
- The local network interface to send multicast messages
- Throws:
SocketException- If an error occurs
- Since:
- 1.4
- See Also:
MulticastSocket.setNetworkInterface(NetworkInterface netIf)
public byte getTTL() throws IOException
Deprecated. 1.2 Replaced by getTimeToLive()
Returns the current value of the "Time to Live" option. This is the number of hops a packet can make before it "expires". This method id deprecated. UsegetTimeToLiveinstead.
- Returns:
- The TTL value
- Throws:
IOException- If an error occurs
- See Also:
getTimeToLive()
public int getTimeToLive() throws IOException
Returns the current value of the "Time to Live" option. This is the number of hops a packet can make before it "expires".
- Returns:
- The TTL value
- Throws:
IOException- If an error occurs
- Since:
- 1.2
public void joinGroup(InetAddress mcastaddr) throws IOException
Joins the specified multicast group.
- Parameters:
mcastaddr- The address of the group to join
- Throws:
IOException- If an error occursSecurityException- If a security manager exists and its checkMulticast method doesn't allow the operation
public void joinGroup(SocketAddress mcastaddr, NetworkInterface netIf) throws IOException
Joins the specified mulitcast group on a specified interface.
- Parameters:
mcastaddr- The multicast address to joinnetIf- The local network interface to receive the multicast messages on or null to defer the interface set by #setInterface or #setNetworkInterface
- Throws:
IOException- If an error occursIllegalArgumentException- If address type is not supportedSecurityException- If a security manager exists and its checkMulticast method doesn't allow the operation
- Since:
- 1.4
- See Also:
MulticastSocket.setInterface(InetAddress addr),MulticastSocket.setNetworkInterface(NetworkInterface netIf)
public void leaveGroup(InetAddress mcastaddr) throws IOException
Leaves the specified multicast group
- Parameters:
mcastaddr- The address of the group to leave
- Throws:
IOException- If an error occursSecurityException- If a security manager exists and its checkMulticast method doesn't allow the operation
public void leaveGroup(SocketAddress mcastaddr, NetworkInterface netIf) throws IOException
Leaves the specified mulitcast group on a specified interface.
- Parameters:
mcastaddr- The multicast address to leavenetIf- The local networki interface or null to defer to the interface set by setInterface or setNetworkInterface
- Throws:
IOException- If an error occursIllegalArgumentException- If address type is not supportedSecurityException- If a security manager exists and its checkMulticast method doesn't allow the operation
- Since:
- 1.4
- See Also:
MulticastSocket.setInterface(InetAddress addr),MulticastSocket.setNetworkInterface(NetworkInterface netIf)
public void send(DatagramPacket packet, byte ttl) throws IOException
Deprecated.
Sends a packet of data to a multicast address with a TTL that is different from the default TTL on this socket. The default TTL for the socket is not changed.
- Parameters:
packet- The packet of data to sendttl- The TTL for this packet
- Throws:
IOException- If an error occursSecurityException- If a security manager exists and its checkConnect or checkMulticast method doesn't allow the operation
public void setInterface(InetAddress addr) throws SocketException
Sets the interface to use for sending multicast packets.
- Parameters:
addr- The new interface to use.
- Throws:
SocketException- If an error occurs.
- Since:
- 1.4
public void setLoopbackMode(boolean disable) throws SocketException
Disable/Enable local loopback of multicast packets. The option is used by the platform's networking code as a hint for setting whether multicast data will be looped back to the local socket. Because this option is a hint, applications that want to verify what loopback mode is set to should call #getLoopbackMode
- Parameters:
disable- True to disable loopback mode
- Throws:
SocketException- If an error occurs
- Since:
- 1.4
public void setNetworkInterface(NetworkInterface netIf) throws SocketException
Sets the local network interface used to send multicast messages
- Parameters:
netIf- The local network interface used to send multicast messages
- Throws:
SocketException- If an error occurs
- Since:
- 1.4
- See Also:
getNetworkInterface()
public void setTTL(byte ttl) throws IOException
Deprecated. 1.2 Replaced by
setTimeToLiveSets the "Time to Live" value for a socket. The value must be between 1 and 255.
- Parameters:
ttl- The new TTL value
- Throws:
IOException- If an error occurs
- See Also:
MulticastSocket.setTimeToLive(int ttl)
public void setTimeToLive(int ttl) throws IOException
Sets the "Time to Live" value for a socket. The value must be between 0 and 255, inclusive.
- Parameters:
ttl- The new TTL value
- Throws:
IOException- If an error occurs
- Since:
- 1.2