java.net
Class MulticastSocket

java.lang.Object sample code for java.lang.Object definition code for java.lang.Object 
  extended by java.net.DatagramSocket sample code for java.net.DatagramSocket definition code for java.net.DatagramSocket 
      extended by java.net.MulticastSocket

public class MulticastSocket
extends DatagramSocket sample code for java.net.DatagramSocket definition code for java.net.DatagramSocket

The multicast datagram socket class is useful for sending and receiving IP multicast packets. A MulticastSocket is a (UDP) DatagramSocket, with additional capabilities for joining "groups" of other multicast hosts on the internet.

A multicast group is specified by a class D IP address and by a standard UDP port number. Class D IP addresses are in the range 224.0.0.0 to 239.255.255.255, inclusive. The address 224.0.0.0 is reserved and should not be used.

One would join a multicast group by first creating a MulticastSocket with the desired port, then invoking the joinGroup(InetAddress groupAddr) method:

 // join a Multicast group and send the group salutations
 ...
 String msg = "Hello";
 InetAddress group = InetAddress.getByName("228.5.6.7");
 MulticastSocket s = new MulticastSocket(6789);
 s.joinGroup(group);
 DatagramPacket hi = new DatagramPacket(msg.getBytes(), msg.length(),
                             group, 6789);
 s.send(hi);
 // get their responses!
 byte[] buf = new byte[1000];
 DatagramPacket recv = new DatagramPacket(buf, buf.length);
 s.receive(recv);
 ...
 // OK, I'm done talking - leave the group...
 s.leaveGroup(group);
 
When one sends a message to a multicast group, all subscribing recipients to that host and port receive the message (within the time-to-live range of the packet, see below). The socket needn't be a member of the multicast group to send messages to it.

When a socket subscribes to a multicast group/port, it receives datagrams sent by other hosts to the group/port, as do all other members of the group and port. A socket relinquishes membership in a group by the leaveGroup(InetAddress addr) method. Multiple MulticastSocket's may subscribe to a multicast group and port concurrently, and they will all receive group datagrams.

Currently applets are not allowed to use multicast sockets.

Since:
JDK1.1

Constructor Summary
MulticastSocket sample code for java.net.MulticastSocket.MulticastSocket() definition code for java.net.MulticastSocket.MulticastSocket() ()
          Create a multicast socket.
MulticastSocket sample code for java.net.MulticastSocket.MulticastSocket(int) definition code for java.net.MulticastSocket.MulticastSocket(int) (int port)
          Create a multicast socket and bind it to a specific port.
MulticastSocket sample code for java.net.MulticastSocket.MulticastSocket(java.net.SocketAddress) definition code for java.net.MulticastSocket.MulticastSocket(java.net.SocketAddress) (SocketAddress sample code for java.net.SocketAddress definition code for java.net.SocketAddress  bindaddr)
          Create a MulticastSocket bound to the specified socket address.
 
Method Summary
 InetAddress sample code for java.net.InetAddress definition code for java.net.InetAddress getInterface sample code for java.net.MulticastSocket.getInterface() definition code for java.net.MulticastSocket.getInterface() ()
          Retrieve the address of the network interface used for multicast packets.
 boolean getLoopbackMode sample code for java.net.MulticastSocket.getLoopbackMode() definition code for java.net.MulticastSocket.getLoopbackMode() ()
          Get the setting for local loopback of multicast datagrams.
 NetworkInterface sample code for java.net.NetworkInterface definition code for java.net.NetworkInterface getNetworkInterface sample code for java.net.MulticastSocket.getNetworkInterface() definition code for java.net.MulticastSocket.getNetworkInterface() ()
          Get the multicast network interface set.
 int getTimeToLive sample code for java.net.MulticastSocket.getTimeToLive() definition code for java.net.MulticastSocket.getTimeToLive() ()
          Get the default time-to-live for multicast packets sent out on the socket.
 byte getTTL sample code for java.net.MulticastSocket.getTTL() definition code for java.net.MulticastSocket.getTTL() ()
          Deprecated. use the getTimeToLive method instead, which returns an int instead of a byte.
 void joinGroup sample code for java.net.MulticastSocket.joinGroup(java.net.InetAddress) definition code for java.net.MulticastSocket.joinGroup(java.net.InetAddress) (InetAddress sample code for java.net.InetAddress definition code for java.net.InetAddress  mcastaddr)
          Joins a multicast group.
 void joinGroup sample code for java.net.MulticastSocket.joinGroup(java.net.SocketAddress, java.net.NetworkInterface) definition code for java.net.MulticastSocket.joinGroup(java.net.SocketAddress, java.net.NetworkInterface) (SocketAddress sample code for java.net.SocketAddress definition code for java.net.SocketAddress  mcastaddr, NetworkInterface sample code for java.net.NetworkInterface definition code for java.net.NetworkInterface  netIf)
          Joins the specified multicast group at the specified interface.
 void leaveGroup sample code for java.net.MulticastSocket.leaveGroup(java.net.InetAddress) definition code for java.net.MulticastSocket.leaveGroup(java.net.InetAddress) (InetAddress sample code for java.net.InetAddress definition code for java.net.InetAddress  mcastaddr)
          Leave a multicast group.
 void leaveGroup sample code for java.net.MulticastSocket.leaveGroup(java.net.SocketAddress, java.net.NetworkInterface) definition code for java.net.MulticastSocket.leaveGroup(java.net.SocketAddress, java.net.NetworkInterface) (SocketAddress sample code for java.net.SocketAddress definition code for java.net.SocketAddress  mcastaddr, NetworkInterface sample code for java.net.NetworkInterface definition code for java.net.NetworkInterface  netIf)
          Leave a multicast group on a specified local interface.
 void send sample code for java.net.MulticastSocket.send(java.net.DatagramPacket, byte) definition code for java.net.MulticastSocket.send(java.net.DatagramPacket, byte) (DatagramPacket sample code for java.net.DatagramPacket definition code for java.net.DatagramPacket  p, byte ttl)
          Deprecated. Use the following code or its equivalent instead: ...... int ttl = mcastSocket.getTimeToLive(); mcastSocket.setTimeToLive(newttl); mcastSocket.send(p); mcastSocket.setTimeToLive(ttl); ......
 void setInterface sample code for java.net.MulticastSocket.setInterface(java.net.InetAddress) definition code for java.net.MulticastSocket.setInterface(java.net.InetAddress) (InetAddress sample code for java.net.InetAddress definition code for java.net.InetAddress  inf)
          Set the multicast network interface used by methods whose behavior would be affected by the value of the network interface.
 void setLoopbackMode sample code for java.net.MulticastSocket.setLoopbackMode(boolean) definition code for java.net.MulticastSocket.setLoopbackMode(boolean) (boolean disable)
          Disable/Enable local loopback of multicast datagrams 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.
 void setNetworkInterface sample code for java.net.MulticastSocket.setNetworkInterface(java.net.NetworkInterface) definition code for java.net.MulticastSocket.setNetworkInterface(java.net.NetworkInterface) (NetworkInterface sample code for java.net.NetworkInterface definition code for java.net.NetworkInterface  netIf)
          Specify the network interface for outgoing multicast datagrams sent on this socket.
 void setTimeToLive sample code for java.net.MulticastSocket.setTimeToLive(int) definition code for java.net.MulticastSocket.setTimeToLive(int) (int ttl)
          Set the default time-to-live for multicast packets sent out on this MulticastSocket in order to control the scope of the multicasts.
 void setTTL sample code for java.net.MulticastSocket.setTTL(byte) definition code for java.net.MulticastSocket.setTTL(byte) (byte ttl)
          Deprecated. use the setTimeToLive method instead, which uses int instead of byte as the type for ttl.
 
Methods inherited from class java.net.DatagramSocket sample code for java.net.DatagramSocket definition code for java.net.DatagramSocket
bind sample code for java.net.DatagramSocket.bind(java.net.SocketAddress) definition code for java.net.DatagramSocket.bind(java.net.SocketAddress) , close sample code for java.net.DatagramSocket.close() definition code for java.net.DatagramSocket.close() , connect sample code for java.net.DatagramSocket.connect(java.net.InetAddress, int) definition code for java.net.DatagramSocket.connect(java.net.InetAddress, int) , connect sample code for java.net.DatagramSocket.connect(java.net.SocketAddress) definition code for java.net.DatagramSocket.connect(java.net.SocketAddress) , disconnect sample code for java.net.DatagramSocket.disconnect() definition code for java.net.DatagramSocket.disconnect() , getBroadcast sample code for java.net.DatagramSocket.getBroadcast() definition code for java.net.DatagramSocket.getBroadcast() , getChannel sample code for java.net.DatagramSocket.getChannel() definition code for java.net.DatagramSocket.getChannel() , getInetAddress sample code for java.net.DatagramSocket.getInetAddress() definition code for java.net.DatagramSocket.getInetAddress() , getLocalAddress sample code for java.net.DatagramSocket.getLocalAddress() definition code for java.net.DatagramSocket.getLocalAddress() , getLocalPort sample code for java.net.DatagramSocket.getLocalPort() definition code for java.net.DatagramSocket.getLocalPort() , getLocalSocketAddress sample code for java.net.DatagramSocket.getLocalSocketAddress() definition code for java.net.DatagramSocket.getLocalSocketAddress() , getPort sample code for java.net.DatagramSocket.getPort() definition code for java.net.DatagramSocket.getPort() , getReceiveBufferSize sample code for java.net.DatagramSocket.getReceiveBufferSize() definition code for java.net.DatagramSocket.getReceiveBufferSize() , getRemoteSocketAddress sample code for java.net.DatagramSocket.getRemoteSocketAddress() definition code for java.net.DatagramSocket.getRemoteSocketAddress() , getReuseAddress sample code for java.net.DatagramSocket.getReuseAddress() definition code for java.net.DatagramSocket.getReuseAddress() , getSendBufferSize sample code for java.net.DatagramSocket.getSendBufferSize() definition code for java.net.DatagramSocket.getSendBufferSize() , getSoTimeout sample code for java.net.DatagramSocket.getSoTimeout() definition code for java.net.DatagramSocket.getSoTimeout() , getTrafficClass sample code for java.net.DatagramSocket.getTrafficClass() definition code for java.net.DatagramSocket.getTrafficClass() , isBound sample code for java.net.DatagramSocket.isBound() definition code for java.net.DatagramSocket.isBound() , isClosed sample code for java.net.DatagramSocket.isClosed() definition code for java.net.DatagramSocket.isClosed() , isConnected sample code for java.net.DatagramSocket.isConnected() definition code for java.net.DatagramSocket.isConnected() , receive sample code for java.net.DatagramSocket.receive(java.net.DatagramPacket) definition code for java.net.DatagramSocket.receive(java.net.DatagramPacket) , send sample code for java.net.DatagramSocket.send(java.net.DatagramPacket) definition code for java.net.DatagramSocket.send(java.net.DatagramPacket) , setBroadcast sample code for java.net.DatagramSocket.setBroadcast(boolean) definition code for java.net.DatagramSocket.setBroadcast(boolean) , setDatagramSocketImplFactory sample code for java.net.DatagramSocket.setDatagramSocketImplFactory(java.net.DatagramSocketImplFactory) definition code for java.net.DatagramSocket.setDatagramSocketImplFactory(java.net.DatagramSocketImplFactory) , setReceiveBufferSize sample code for java.net.DatagramSocket.setReceiveBufferSize(int) definition code for java.net.DatagramSocket.setReceiveBufferSize(int) , setReuseAddress sample code for java.net.DatagramSocket.setReuseAddress(boolean) definition code for java.net.DatagramSocket.setReuseAddress(boolean) , setSendBufferSize sample code for java.net.DatagramSocket.setSendBufferSize(int) definition code for java.net.DatagramSocket.setSendBufferSize(int) , setSoTimeout sample code for java.net.DatagramSocket.setSoTimeout(int) definition code for java.net.DatagramSocket.setSoTimeout(int) , setTrafficClass sample code for java.net.DatagramSocket.setTrafficClass(int) definition code for java.net.DatagramSocket.setTrafficClass(int)
 
Methods inherited from class java.lang.Object sample code for java.lang.Object definition code for java.lang.Object
clone sample code for java.lang.Object.clone() definition code for java.lang.Object.clone() , equals sample code for java.lang.Object.equals(java.lang.Object) definition code for java.lang.Object.equals(java.lang.Object) , finalize sample code for java.lang.Object.finalize() definition code for java.lang.Object.finalize() , getClass sample code for java.lang.Object.getClass() definition code for java.lang.Object.getClass() , hashCode sample code for java.lang.Object.hashCode() definition code for java.lang.Object.hashCode() , notify sample code for java.lang.Object.notify() definition code for java.lang.Object.notify() , notifyAll sample code for java.lang.Object.notifyAll() definition code for java.lang.Object.notifyAll() , toString sample code for java.lang.Object.toString() definition code for java.lang.Object.toString() , wait sample code for java.lang.Object.wait() definition code for java.lang.Object.wait() , wait sample code for java.lang.Object.wait(long) definition code for java.lang.Object.wait(long) , wait sample code for java.lang.Object.wait(long, int) definition code for java.lang.Object.wait(long, int)
 

Constructor Detail

MulticastSocket sample code for java.net.MulticastSocket() definition code for java.net.MulticastSocket()

public MulticastSocket()
                throws IOException sample code for java.io.IOException definition code for java.io.IOException 
Create a multicast socket.

If there is a security manager, its checkListen method is first called with 0 as its argument to ensure the operation is allowed. This could result in a SecurityException.

When the socket is created the DatagramSocket.setReuseAddress(boolean) sample code for java.net.DatagramSocket.setReuseAddress(boolean) definition code for java.net.DatagramSocket.setReuseAddress(boolean) method is called to enable the SO_REUSEADDR socket option.

Throws:
IOException sample code for java.io.IOException definition code for java.io.IOException - if an I/O exception occurs while creating the MulticastSocket
SecurityException sample code for java.lang.SecurityException definition code for java.lang.SecurityException - if a security manager exists and its checkListen method doesn't allow the operation.
See Also:
SecurityManager.checkListen(int) sample code for java.lang.SecurityManager.checkListen(int) definition code for java.lang.SecurityManager.checkListen(int) , DatagramSocket.setReuseAddress(boolean) sample code for java.net.DatagramSocket.setReuseAddress(boolean) definition code for java.net.DatagramSocket.setReuseAddress(boolean)

MulticastSocket sample code for java.net.MulticastSocket(int) definition code for java.net.MulticastSocket(int)

public MulticastSocket(int port)
                throws IOException sample code for java.io.IOException definition code for java.io.IOException 
Create a multicast socket and bind it to a specific port.

If there is a security manager, its checkListen method is first called with the port argument as its argument to ensure the operation is allowed. This could result in a SecurityException.

When the socket is created the DatagramSocket.setReuseAddress(boolean) sample code for java.net.DatagramSocket.setReuseAddress(boolean) definition code for java.net.DatagramSocket.setReuseAddress(boolean) method is called to enable the SO_REUSEADDR socket option.

Parameters:
port - port to use
Throws:
IOException sample code for java.io.IOException definition code for java.io.IOException - if an I/O exception occurs while creating the MulticastSocket
SecurityException sample code for java.lang.SecurityException definition code for java.lang.SecurityException - if a security manager exists and its checkListen method doesn't allow the operation.
See Also:
SecurityManager.checkListen(int) sample code for java.lang.SecurityManager.checkListen(int) definition code for java.lang.SecurityManager.checkListen(int) , DatagramSocket.setReuseAddress(boolean) sample code for java.net.DatagramSocket.setReuseAddress(boolean) definition code for java.net.DatagramSocket.setReuseAddress(boolean)

MulticastSocket sample code for java.net.MulticastSocket(java.net.SocketAddress) definition code for java.net.MulticastSocket(java.net.SocketAddress)

public MulticastSocket(SocketAddress sample code for java.net.SocketAddress definition code for java.net.SocketAddress  bindaddr)
                throws IOException sample code for java.io.IOException definition code for java.io.IOException 
Create a MulticastSocket bound to the specified socket address.

Or, if the address is null, create an unbound socket.

If there is a security manager, its checkListen method is first called with the SocketAddress port as its argument to ensure the operation is allowed. This could result in a SecurityException.

When the socket is created the DatagramSocket.setReuseAddress(boolean) sample code for java.net.DatagramSocket.setReuseAddress(boolean) definition code for java.net.DatagramSocket.setReuseAddress(boolean) method is called to enable the SO_REUSEADDR socket option.

Parameters:
bindaddr - Socket address to bind to, or null for an unbound socket.
Throws:
IOException sample code for java.io.IOException definition code for java.io.IOException - if an I/O exception occurs while creating the MulticastSocket
SecurityException sample code for java.lang.SecurityException definition code for java.lang.SecurityException - if a security manager exists and its checkListen method doesn't allow the operation.
Since:
1.4
See Also:
SecurityManager.checkListen(int) sample code for java.lang.SecurityManager.checkListen(int) definition code for java.lang.SecurityManager.checkListen(int) , DatagramSocket.setReuseAddress(boolean) sample code for java.net.DatagramSocket.setReuseAddress(boolean) definition code for java.net.DatagramSocket.setReuseAddress(boolean)
Method Detail

setTTL sample code for java.net.MulticastSocket.setTTL(byte) definition code for java.net.MulticastSocket.setTTL(byte)

@Deprecated
public void setTTL(byte ttl)
            throws IOException sample code for java.io.IOException definition code for java.io.IOException 
Deprecated. use the setTimeToLive method instead, which uses int instead of byte as the type for ttl.

Set the default time-to-live for multicast packets sent out on this MulticastSocket in order to control the scope of the multicasts.

The ttl is an unsigned 8-bit quantity, and so must be in the range 0 <= ttl <= 0xFF .

Parameters:
ttl - the time-to-live
Throws:
IOException sample code for java.io.IOException definition code for java.io.IOException - if an I/O exception occurs while setting the default time-to-live value
See Also:
getTTL() sample code for java.net.MulticastSocket.getTTL() definition code for java.net.MulticastSocket.getTTL()

setTimeToLive sample code for java.net.MulticastSocket.setTimeToLive(int) definition code for java.net.MulticastSocket.setTimeToLive(int)

public void setTimeToLive(int ttl)
                   throws IOException sample code for java.io.IOException definition code for java.io.IOException 
Set the default time-to-live for multicast packets sent out on this MulticastSocket in order to control the scope of the multicasts.

The ttl must be in the range 0 <= ttl <= 255 or an IllegalArgumentException will be thrown.

Parameters:
ttl - the time-to-live
Throws:
IOException sample code for java.io.IOException definition code for java.io.IOException - if an I/O exception occurs while setting the default time-to-live value
See Also:
getTimeToLive() sample code for java.net.MulticastSocket.getTimeToLive() definition code for java.net.MulticastSocket.getTimeToLive()

getTTL sample code for java.net.MulticastSocket.getTTL() definition code for java.net.MulticastSocket.getTTL()

@Deprecated
public byte getTTL()
            throws IOException sample code for java.io.IOException definition code for java.io.IOException 
Deprecated. use the getTimeToLive method instead, which returns an int instead of a byte.

Get the default time-to-live for multicast packets sent out on the socket.

Returns:
the default time-to-live value
Throws:
IOException sample code for java.io.IOException definition code for java.io.IOException - if an I/O exception occurs while getting the default time-to-live value
See Also:
setTTL(byte) sample code for java.net.MulticastSocket.setTTL(byte) definition code for java.net.MulticastSocket.setTTL(byte)

getTimeToLive sample code for java.net.MulticastSocket.getTimeToLive() definition code for java.net.MulticastSocket.getTimeToLive()

public int getTimeToLive()
                  throws IOException sample code for java.io.IOException definition code for java.io.IOException 
Get the default time-to-live for multicast packets sent out on the socket.

Returns:
the default time-to-live value
Throws:
IOException sample code for java.io.IOException definition code for java.io.IOException - if an I/O exception occurs while getting the default time-to-live value
See Also:
setTimeToLive(int) sample code for java.net.MulticastSocket.setTimeToLive(int) definition code for java.net.MulticastSocket.setTimeToLive(int)

joinGroup sample code for java.net.MulticastSocket.joinGroup(java.net.InetAddress) definition code for java.net.MulticastSocket.joinGroup(java.net.InetAddress)

public void joinGroup(InetAddress sample code for java.net.InetAddress definition code for java.net.InetAddress  mcastaddr)
               throws IOException sample code for java.io.IOException definition code for java.io.IOException 
Joins a multicast group. Its behavior may be affected by setInterface or setNetworkInterface.

If there is a security manager, this method first calls its checkMulticast method with the mcastaddr argument as its argument.

Parameters:
mcastaddr - is the multicast address to join
Throws:
IOException sample code for java.io.IOException definition code for java.io.IOException - if there is an error joining or when the address is not a multicast address.
SecurityException sample code for java.lang.SecurityException definition code for java.lang.SecurityException - if a security manager exists and its checkMulticast method doesn't allow the join.
See Also:
SecurityManager.checkMulticast(InetAddress) sample code for java.lang.SecurityManager.checkMulticast(java.net.InetAddress) definition code for java.lang.SecurityManager.checkMulticast(java.net.InetAddress)

leaveGroup sample code for java.net.MulticastSocket.leaveGroup(java.net.InetAddress) definition code for java.net.MulticastSocket.leaveGroup(java.net.InetAddress)

public void leaveGroup(InetAddress sample code for java.net.InetAddress definition code for java.net.InetAddress  mcastaddr)
                throws IOException sample code for java.io.IOException definition code for java.io.IOException 
Leave a multicast group. Its behavior may be affected by setInterface or setNetworkInterface.

If there is a security manager, this method first calls its checkMulticast method with the mcastaddr argument as its argument.

Parameters:
mcastaddr - is the multicast address to leave
Throws:
IOException sample code for java.io.IOException definition code for java.io.IOException - if there is an error leaving or when the address is not a multicast address.
SecurityException sample code for java.lang.SecurityException definition code for java.lang.SecurityException - if a security manager exists and its checkMulticast method doesn't allow the operation.
See Also:
SecurityManager.checkMulticast(InetAddress) sample code for java.lang.SecurityManager.checkMulticast(java.net.InetAddress) definition code for java.lang.SecurityManager.checkMulticast(java.net.InetAddress)

joinGroup sample code for java.net.MulticastSocket.joinGroup(java.net.SocketAddress, java.net.NetworkInterface) definition code for java.net.MulticastSocket.joinGroup(java.net.SocketAddress, java.net.NetworkInterface)

public void joinGroup(SocketAddress sample code for java.net.SocketAddress definition code for java.net.SocketAddress  mcastaddr,
                      NetworkInterface sample code for java.net.NetworkInterface definition code for java.net.NetworkInterface  netIf)
               throws IOException sample code for java.io.IOException definition code for java.io.IOException 
Joins the specified multicast group at the specified interface.

If there is a security manager, this method first calls its checkMulticast method with the mcastaddr argument as its argument.

Parameters:
mcastaddr - is the multicast address to join
netIf - specifies the local interface to receive multicast datagram packets, or null to defer to the interface set by setInterface(InetAddress) sample code for java.net.MulticastSocket.setInterface(java.net.InetAddress) definition code for java.net.MulticastSocket.setInterface(java.net.InetAddress) or setNetworkInterface(NetworkInterface) sample code for java.net.MulticastSocket.setNetworkInterface(java.net.NetworkInterface) definition code for java.net.MulticastSocket.setNetworkInterface(java.net.NetworkInterface)
Throws:
IOException sample code for java.io.IOException definition code for java.io.IOException - if there is an error joining or when the address is not a multicast address.
SecurityException sample code for java.lang.SecurityException definition code for java.lang.SecurityException - if a security manager exists and its checkMulticast method doesn't allow the join.
IllegalArgumentException sample code for java.lang.IllegalArgumentException definition code for java.lang.IllegalArgumentException - if mcastaddr is null or is a SocketAddress subclass not supported by this socket
Since:
1.4
See Also:
SecurityManager.checkMulticast(InetAddress) sample code for java.lang.SecurityManager.checkMulticast(java.net.InetAddress) definition code for java.lang.SecurityManager.checkMulticast(java.net.InetAddress)

leaveGroup sample code for java.net.MulticastSocket.leaveGroup(java.net.SocketAddress, java.net.NetworkInterface) definition code for java.net.MulticastSocket.leaveGroup(java.net.SocketAddress, java.net.NetworkInterface)

public void leaveGroup(SocketAddress sample code for java.net.SocketAddress definition code for java.net.SocketAddress  mcastaddr,
                       NetworkInterface sample code for java.net.NetworkInterface definition code for java.net.NetworkInterface  netIf)
                throws IOException sample code for java.io.IOException definition code for java.io.IOException 
Leave a multicast group on a specified local interface.

If there is a security manager, this method first calls its checkMulticast method with the mcastaddr argument as its argument.

Parameters:
mcastaddr - is the multicast address to leave
netIf - specifies the local interface or null to defer to the interface set by setInterface(InetAddress) sample code for java.net.MulticastSocket.setInterface(java.net.InetAddress) definition code for java.net.MulticastSocket.setInterface(java.net.InetAddress) or setNetworkInterface(NetworkInterface) sample code for java.net.MulticastSocket.setNetworkInterface(java.net.NetworkInterface) definition code for java.net.MulticastSocket.setNetworkInterface(java.net.NetworkInterface)
Throws:
IOException sample code for java.io.IOException definition code for java.io.IOException - if there is an error leaving or when the address is not a multicast address.
SecurityException sample code for java.lang.SecurityException definition code for java.lang.SecurityException - if a security manager exists and its checkMulticast method doesn't allow the operation.
IllegalArgumentException sample code for java.lang.IllegalArgumentException definition code for java.lang.IllegalArgumentException - if mcastaddr is null or is a SocketAddress subclass not supported by this socket
Since:
1.4
See Also:
SecurityManager.checkMulticast(InetAddress) sample code for java.lang.SecurityManager.checkMulticast(java.net.InetAddress) definition code for java.lang.SecurityManager.checkMulticast(java.net.InetAddress)

setInterface sample code for java.net.MulticastSocket.setInterface(java.net.InetAddress) definition code for java.net.MulticastSocket.setInterface(java.net.InetAddress)

public void setInterface(InetAddress sample code for java.net.InetAddress definition code for java.net.InetAddress  inf)
                  throws SocketException sample code for java.net.SocketException definition code for java.net.SocketException 
Set the multicast network interface used by methods whose behavior would be affected by the value of the network interface. Useful for multihomed hosts.

Parameters:
inf - the InetAddress
Throws:
SocketException sample code for java.net.SocketException definition code for java.net.SocketException - if there is an error in the underlying protocol, such as a TCP error.
See Also:
getInterface() sample code for java.net.MulticastSocket.getInterface() definition code for java.net.MulticastSocket.getInterface()

getInterface sample code for java.net.MulticastSocket.getInterface() definition code for java.net.MulticastSocket.getInterface()

public InetAddress sample code for java.net.InetAddress definition code for java.net.InetAddress  getInterface()
                         throws SocketException sample code for java.net.SocketException definition code for java.net.SocketException 
Retrieve the address of the network interface used for multicast packets.

Returns:
An InetAddress representing the address of the network interface used for multicast packets.
Throws:
SocketException sample code for java.net.SocketException definition code for java.net.SocketException - if there is an error in the underlying protocol, such as a TCP error.
See Also:
setInterface(java.net.InetAddress) sample code for java.net.MulticastSocket.setInterface(java.net.InetAddress) definition code for java.net.MulticastSocket.setInterface(java.net.InetAddress)

setNetworkInterface sample code for java.net.MulticastSocket.setNetworkInterface(java.net.NetworkInterface) definition code for java.net.MulticastSocket.setNetworkInterface(java.net.NetworkInterface)

public void setNetworkInterface(NetworkInterface sample code for java.net.NetworkInterface definition code for java.net.NetworkInterface  netIf)
                         throws SocketException sample code for java.net.SocketException definition code for java.net.SocketException 
Specify the network interface for outgoing multicast datagrams sent on this socket.

Parameters:
netIf - the interface
Throws:
SocketException sample code for java.net.SocketException definition code for java.net.SocketException - if there is an error in the underlying protocol, such as a TCP error.
Since:
1.4
See Also:
getNetworkInterface() sample code for java.net.MulticastSocket.getNetworkInterface() definition code for java.net.MulticastSocket.getNetworkInterface()