p2ps.imp.net.inet
Class InetMulticastSocket

java.lang.Object
  extended byp2ps.imp.net.inet.InetDatagramSocket
      extended byp2ps.imp.net.inet.InetMulticastSocket
All Implemented Interfaces:
DatagramSocket, MulticastSocket

public class InetMulticastSocket
extends InetDatagramSocket
implements MulticastSocket

A multicast socket implementation that binds to java.net.MulticastSocket

Version:
$Revision: 295 $
Author:
Ian Wang

Constructor Summary
InetMulticastSocket(java.net.MulticastSocket socket)
           
 
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 class p2ps.imp.net.inet.InetDatagramSocket
bind, close, connect, disconnect, getLocalPort, getLocalSocketAddress, getPort, getReceiveBufferSize, getRemoteSocketAddress, getReuseAddress, getSendBufferSize, getSoTimeout, isBound, isClosed, isConnected, newPacket, newPacket, receive, send, setReceiveBufferSize, setReuseAddress, setSendBufferSize, setSoTimeout
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
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
 

Constructor Detail

InetMulticastSocket

public InetMulticastSocket(java.net.MulticastSocket socket)
                    throws java.io.IOException
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.

Specified by:
joinGroup in interface MulticastSocket
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.

Specified by:
leaveGroup in interface MulticastSocket
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.

Specified by:
getNetworkInterface in interface MulticastSocket
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.

Specified by:
setNetworkInterface in interface MulticastSocket
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.

Specified by:
getTimeToLive in interface MulticastSocket
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.

Specified by:
setTimeToLive in interface MulticastSocket
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.

Specified by:
getLoopbackMode in interface MulticastSocket
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()

Specified by:
setLoopbackMode in interface MulticastSocket
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()