p2ps.imp.net
Interface MulticastSocket

All Superinterfaces:
DatagramSocket
All Known Implementing Classes:
InetMulticastSocket

public interface MulticastSocket
extends DatagramSocket

An interface to an underlying multicast socket. This interface has many of the same methods as java.net.MulticastSocket, but allows different datagram socket implementations to be plugged in.

Version:
$Revision: 295 $
Author:
Ian Wang

Method Summary
 boolean getLoopbackMode()
          Get the setting for local loopback of multicast datagrams.
 java.net.NetworkInterface getNetworkInterface()
          Get the multicast network interface set.
 int getTimeToLive()
          Get the default time-to-live for multicast packets sent out on the socket.
 void joinGroup(java.net.SocketAddress mcastaddr, java.net.NetworkInterface netIf)
          Joins the specified multicast group at the specified interface.
 void leaveGroup(java.net.SocketAddress mcastaddr, java.net.NetworkInterface netIf)
          Leave a multicast group on a specified local interface.
 void setLoopbackMode(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(java.net.NetworkInterface netIf)
          Specify the network interface for outgoing multicast datagrams sent on this socket.
 void setTimeToLive(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.
 
Methods inherited from interface p2ps.imp.net.DatagramSocket
bind, close, connect, disconnect, getLocalPort, getLocalSocketAddress, getPort, getReceiveBufferSize, getRemoteSocketAddress, getReuseAddress, getSendBufferSize, getSoTimeout, isBound, isClosed, isConnected, newPacket, newPacket, receive, send, setReceiveBufferSize, setReuseAddress, setSendBufferSize, setSoTimeout
 

Method Detail

joinGroup

public void joinGroup(java.net.SocketAddress mcastaddr,
                      java.net.NetworkInterface netIf)
               throws 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 MulticastSocket.setInterface(java.net.InetAddress) or MulticastSocket.setNetworkInterface(java.net.NetworkInterface)
Throws:
java.io.IOException - if there is an error joining or when the address is not a multicast address.
java.lang.SecurityException - if a security manager exists and its checkMulticast method doesn't allow the join.
java.lang.IllegalArgumentException - if mcastaddr is null or is a SocketAddress subclass not supported by this socket
Since:
1.4
See Also:
SecurityManager.checkMulticast(java.net.InetAddress)

leaveGroup

public void leaveGroup(java.net.SocketAddress mcastaddr,
                       java.net.NetworkInterface netIf)
                throws 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 MulticastSocket.setInterface(java.net.InetAddress) or MulticastSocket.setNetworkInterface(java.net.NetworkInterface)
Throws:
java.io.IOException - if there is an error leaving or when the address is not a multicast address.
java.lang.SecurityException - if a security manager exists and its checkMulticast method doesn't allow the operation.
java.lang.IllegalArgumentException - if mcastaddr is null or is a SocketAddress subclass not supported by this socket
Since:
1.4
See Also:
SecurityManager.checkMulticast(java.net.InetAddress)

getNetworkInterface

public java.net.NetworkInterface getNetworkInterface()
                                              throws java.net.SocketException
Get the multicast network interface set.

Returns:
the multicast NetworkInterface currently set
Throws:
java.net.SocketException - if there is an error in the underlying protocol, such as a TCP error.
Since:
1.4
See Also:
setNetworkInterface(java.net.NetworkInterface)

setNetworkInterface

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

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

getTimeToLive

public int getTimeToLive()
                  throws 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:
java.io.IOException - if an I/O exception occurs while getting the default time-to-live value
See Also:
setTimeToLive(int)

setTimeToLive

public void setTimeToLive(int ttl)
                   throws 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:
java.io.IOException - if an I/O exception occurs while setting the default time-to-live value
See Also:
getTimeToLive()

getLoopbackMode

public boolean getLoopbackMode()
                        throws java.net.SocketException
Get the setting for local loopback of multicast datagrams.

Returns:
true if the LoopbackMode has been disabled
Throws:
java.net.SocketException - if an error occurs while getting the value
Since:
1.4
See Also:
setLoopbackMode(boolean)

setLoopbackMode

public void setLoopbackMode(boolean disable)
                     throws java.net.SocketException
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.

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 the LoopbackMode
Throws:
java.net.SocketException - if an error occurs while setting the value
Since:
1.4
See Also:
getLoopbackMode()