Build 1.0_r1(from source)

java.net
Class MulticastSocket

java.lang.Object
  extended by java.net.DatagramSocket
      extended by java.net.MulticastSocket

public class MulticastSocket
extends DatagramSocket

This class models a multicast socket for sending & receiving datagram packets to a multicast group.

See Also:
DatagramSocket

Field Summary
(package private) static int SO_REUSEPORT
           
 
Fields inherited from class java.net.DatagramSocket
address, factory, impl, isBound, port
 
Constructor Summary
MulticastSocket()
          Constructs a multicast socket, bound to any available port on the localhost.
MulticastSocket(int aPort)
          Returns a multicast socket, bound to the nominated port on the localhost.
MulticastSocket(SocketAddress localAddr)
          Constructs a MulticastSocket bound to the host/port specified by the SocketAddress, or an unbound DatagramSocket if the SocketAddress is null.
 
Method Summary
(package private)  void createSocket(int aPort, InetAddress addr)
           
 InetAddress getInterface()
          Answer the network address used by the socket.
 boolean getLoopbackMode()
          Get the state of the IP_MULTICAST_LOOP socket option.
 NetworkInterface getNetworkInterface()
          Answer the network interface used by the socket.
 int getTimeToLive()
          Answer the time-to-live (TTL) for multicast packets sent on this socket.
 byte getTTL()
          Deprecated. Replaced by getTimeToLive()
(package private)  boolean isMulticastSocket()
          Returns whether this socket is multicast.
 void joinGroup(InetAddress groupAddr)
          Add this socket to the multicast group.
 void joinGroup(SocketAddress groupAddress, NetworkInterface netInterface)
          Add this socket to the multicast group.
 void leaveGroup(InetAddress groupAddr)
          Remove the socket from the multicast group.
 void leaveGroup(SocketAddress groupAddress, NetworkInterface netInterface)
          Remove the socket from the multicast group.
 void send(DatagramPacket pack, byte ttl)
          Deprecated. use setTimeToLive(int)
 void setInterface(InetAddress addr)
          Set the network address used by the socket.
 void setLoopbackMode(boolean loop)
          Set the IP_MULTICAST_LOOP socket option.
 void setNetworkInterface(NetworkInterface netInterface)
          Set the network interface used by the socket.
 void setTimeToLive(int ttl)
          Set the time-to-live (TTL) for multicast packets sent on this socket.
 void setTTL(byte ttl)
          Deprecated. Replaced by setTimeToLive(int)
 
Methods inherited from class java.net.DatagramSocket
bind, checkClosedAndBind, checkListen, 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
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SO_REUSEPORT

static final int SO_REUSEPORT
See Also:
Constant Field Values
Constructor Detail

MulticastSocket

public MulticastSocket()
                throws IOException
Constructs a multicast socket, bound to any available port on the localhost.

Throws:
IOException - if a problem occurs creating or binding the socket

MulticastSocket

public MulticastSocket(int aPort)
                throws IOException
Returns a multicast socket, bound to the nominated port on the localhost.

Parameters:
aPort - the port to bind on the localhost
Throws:
IOException - if a problem occurs creating or binding the socket

MulticastSocket

public MulticastSocket(SocketAddress localAddr)
                throws IOException
Constructs a MulticastSocket bound to the host/port specified by the SocketAddress, or an unbound DatagramSocket if the SocketAddress is null.

Parameters:
localAddr - the local machine address and port to bind to
Throws:
IllegalArgumentException - if the SocketAddress is not supported
IOException - if a problem occurs creating or binding the socket
Since:
1.4
Method Detail

getInterface

public InetAddress getInterface()
                         throws SocketException
Answer the network address used by the socket. This is useful on multi-homed machines.

Returns:
java.net.InetAddress the network address
Throws:
SocketException - The exception thrown while getting the address

getNetworkInterface

public NetworkInterface getNetworkInterface()
                                     throws SocketException
Answer the network interface used by the socket. This is useful on multi-homed machines.

Returns:
java.net.NetworkInterface the network address
Throws:
SocketException - The exception thrown while getting the address
Since:
1.4

getTimeToLive

public int getTimeToLive()
                  throws IOException
Answer the time-to-live (TTL) for multicast packets sent on this socket.

Returns:
java.net.InetAddress
Throws:
IOException - The exception description.

getTTL

@Deprecated
public byte getTTL()
            throws IOException
Deprecated. Replaced by getTimeToLive()

Answer the time-to-live (TTL) for multicast packets sent on this socket.

Returns:
java.net.InetAddress
Throws:
IOException - The exception description.
See Also:
getTimeToLive()

isMulticastSocket

boolean isMulticastSocket()
Description copied from class: DatagramSocket
Returns whether this socket is multicast.

Overrides:
isMulticastSocket in class DatagramSocket
Returns:
Always returns false.

joinGroup

public void joinGroup(InetAddress groupAddr)
               throws IOException
Add this socket to the multicast group. A socket must joint a group before data may be received. A socket may be a member of multiple groups but may join any group once.

Parameters:
groupAddr - the multicast group to be joined
Throws:
IOException - may be thrown while joining a group

joinGroup

public void joinGroup(SocketAddress groupAddress,
                      NetworkInterface netInterface)
               throws IOException
Add this socket to the multicast group. A socket must join a group before data may be received. A socket may be a member of multiple groups but may join any group once.

Parameters:
groupAddress - the multicast group to be joined
netInterface - the network interface on which the addresses should be dropped
Throws:
IOException - will be thrown if address is not a multicast address
SecurityException - will be thrown if caller is not authorized to join group
IllegalArgumentException - will be through if groupAddr is null
Since:
1.4

leaveGroup

public void leaveGroup(InetAddress groupAddr)
                throws IOException
Remove the socket from the multicast group.

Parameters:
groupAddr - the multicast group to be left
Throws:
IOException - will be thrown if address is not a multicast address
SecurityException - will be thrown if caller is not authorized to join group
IllegalArgumentException - will be through if groupAddr is null

leaveGroup

public void leaveGroup(SocketAddress groupAddress,
                       NetworkInterface netInterface)
                throws IOException
Remove the socket from the multicast group.

Parameters:
groupAddress - the multicast group to be left
netInterface - the network interface on which the addresses should be dropped
Throws:
IOException - will be thrown if address is not a multicast address
SecurityException - will be thrown if caller is not authorized to join group
IllegalArgumentException - will be through if groupAddr is null
Since:
1.4

send

@Deprecated
public void send(DatagramPacket pack,
                            byte ttl)
          throws IOException
Deprecated. use setTimeToLive(int)

Send the packet on this socket. The packet must satisfy the security policy before it may be sent.

Parameters:
pack - the DatagramPacket to send
ttl - the TTL setting for this transmission, overriding the socket default
Throws:
IOException - If a send error occurs.

setInterface

public void setInterface(InetAddress addr)
                  throws SocketException
Set the network address used by the socket. This is useful on multi-homed machines.

Parameters:
addr - java.net.InetAddress the interface network address
Throws:
SocketException - the exception may be thrown while setting the address

setNetworkInterface

public void setNetworkInterface(NetworkInterface netInterface)
                         throws SocketException
Set the network interface used by the socket. This is useful on multi-homed machines.

Parameters:
netInterface - NetworkInterface the interface to be used
Throws:
SocketException - the exception may be thrown while setting the address
Since:
1.4

setTimeToLive

public void setTimeToLive(int ttl)
                   throws IOException
Set the time-to-live (TTL) for multicast packets sent on this socket.

Parameters:
ttl - the time-to-live, 0<><= 255="">
Throws:
IOException - The exception thrown while setting the TTL

setTTL

@Deprecated
public void setTTL(byte ttl)
            throws IOException
Deprecated. Replaced by setTimeToLive(int)

Set the time-to-live (TTL) for multicast packets sent on this socket.

Parameters:
ttl - the time-to-live, 0<= 255="">
Throws:
IOException - The exception thrown while setting the TTL
See Also:
setTimeToLive(int)

createSocket

void createSocket(int aPort,
                  InetAddress addr)
            throws SocketException
Overrides:
createSocket in class DatagramSocket
Throws:
SocketException

getLoopbackMode

public boolean getLoopbackMode()
                        throws SocketException
Get the state of the IP_MULTICAST_LOOP socket option.

Returns:
true if the IP_MULTICAST_LOOP is enabled, false otherwise.
Throws:
SocketException - if the socket is closed or the option is invalid.
Since:
1.4

setLoopbackMode

public void setLoopbackMode(boolean loop)
                     throws SocketException
Set the IP_MULTICAST_LOOP socket option.

Parameters:
loop - the socket IP_MULTICAST_LOOP option setting
Throws:
SocketException - if the socket is closed or the option is invalid.
Since:
1.4

Build 1.0_r1(from source)

Please submit a feedback, bug or feature