Build 1.1_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 implements a multicast socket for sending and receiving IP multicast datagram packets.

Since:
Android 1.0
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)
          Constructs a multicast socket, bound to the specified 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()
          Gets the network address used by this socket.
 boolean getLoopbackMode()
          Gets the state of the SocketOptions.IP_MULTICAST_LOOP.
 NetworkInterface getNetworkInterface()
          Gets the network interface used by this socket.
 int getTimeToLive()
          Gets the time-to-live (TTL) for multicast packets sent on this socket.
 byte getTTL()
          Deprecated. Replaced by getTimeToLive()
(package private)  boolean isMulticastSocket()
          Indicates whether this socket is multicast or not.
 void joinGroup(InetAddress groupAddr)
          Adds this socket to the specified multicast group.
 void joinGroup(SocketAddress groupAddress, NetworkInterface netInterface)
          Adds this socket to the specified multicast group.
 void leaveGroup(InetAddress groupAddr)
          Removes this socket from the specified multicast group.
 void leaveGroup(SocketAddress groupAddress, NetworkInterface netInterface)
          Removes this socket from the specified multicast group.
 void send(DatagramPacket pack, byte ttl)
          Deprecated. use setTimeToLive(int).
 void setInterface(InetAddress addr)
          Sets the interface address used by this socket.
 void setLoopbackMode(boolean loop)
          Sets the SocketOptions.IP_MULTICAST_LOOP.
 void setNetworkInterface(NetworkInterface netInterface)
          Sets the network interface used by this socket.
 void setTimeToLive(int ttl)
          Sets 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 an error occurs creating or binding the socket.
Since:
Android 1.0

MulticastSocket

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

Parameters:
aPort - the port to bind on the localhost.
Throws:
IOException - if an error occurs creating or binding the socket.
Since:
Android 1.0

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 an error occurs creating or binding the socket.
Since:
Android 1.0
Method Detail

getInterface

public InetAddress getInterface()
                         throws SocketException
Gets the network address used by this socket. This is useful on multihomed machines.

Returns:
the address of the network interface through which the datagram packets are sent or received.
Throws:
SocketException - if an error occurs while getting the interface address.
Since:
Android 1.0

getNetworkInterface

public NetworkInterface getNetworkInterface()
                                     throws SocketException
Gets the network interface used by this socket. This is useful on multihomed machines.

Returns:
the network interface used by this socket or null if no interface is set.
Throws:
SocketException - if an error occurs while getting the interface.
Since:
Android 1.0

getTimeToLive

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

Returns:
the default value for the time-to-life field.
Throws:
IOException - if an error occurs reading the default value.
Since:
Android 1.0

getTTL

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

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

Returns:
the default value for the time-to-life field.
Throws:
IOException - if an error occurs reading the default value.
Since:
Android 1.0
See Also:
getTimeToLive()

isMulticastSocket

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

Overrides:
isMulticastSocket in class DatagramSocket
Returns:
the return value is always false.

joinGroup

public void joinGroup(InetAddress groupAddr)
               throws IOException
Adds this socket to the specified 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 only once.

Parameters:
groupAddr - the multicast group to be joined.
Throws:
IOException - if an error occurs while joining a group.
Since:
Android 1.0

joinGroup

public void joinGroup(SocketAddress groupAddress,
                      NetworkInterface netInterface)
               throws IOException
Adds this socket to the specified 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 only once.

Parameters:
groupAddress - the multicast group to be joined.
netInterface - the network interface on which the datagram packets will be received.
Throws:
IOException - if the specified address is not a multicast address.
SecurityException - if the caller is not authorized to join the group.
IllegalArgumentException - if no multicast group is specified.
Since:
Android 1.0

leaveGroup

public void leaveGroup(InetAddress groupAddr)
                throws IOException
Removes this socket from the specified multicast group.

Parameters:
groupAddr - the multicast group to be left.
Throws:
IOException - if the specified group address is not a multicast address.
SecurityException - if the caller is not authorized to leave the group.
Since:
Android 1.0

leaveGroup

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

Parameters:
groupAddress - the multicast group to be left.
netInterface - the network interface on which the addresses should be dropped.
Throws:
IOException - if the specified group address is not a multicast address.
SecurityException - if the caller is not authorized to leave the group.
IllegalArgumentException - if no multicast group is specified.
Since:
Android 1.0

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 an error occurs while sending data or setting options.
Since:
Android 1.0

setInterface

public void setInterface(InetAddress addr)
                  throws SocketException
Sets the interface address used by this socket. This allows to send multicast packets on a different interface than the default interface of the local system. This is useful on multihomed machines.

Parameters:
addr - the multicast interface network address to set.
Throws:
SocketException - if an error occurs while setting the network interface address option.
Since:
Android 1.0

setNetworkInterface

public void setNetworkInterface(NetworkInterface netInterface)
                         throws SocketException
Sets the network interface used by this socket. This is useful for multihomed machines.

Parameters:
netInterface - the multicast network interface to set.
Throws:
SocketException - if an error occurs while setting the network interface option.
Since:
Android 1.0

setTimeToLive

public void setTimeToLive(int ttl)
                   throws IOException
Sets the time-to-live (TTL) for multicast packets sent on this socket. Valid TTL values are between 0 and 255 inclusive.

Parameters:
ttl - the default time-to-live field value for packets sent on this socket. 0 <= ttl <= 255.
Throws:
IOException - if an error occurs while setting the TTL option value.
Since:
Android 1.0

setTTL

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

Sets the time-to-live (TTL) for multicast packets sent on this socket. Valid TTL values are between 0 and 255 inclusive.

Parameters:
ttl - the default time-to-live field value for packets sent on this socket: 0 <= ttl <= 255.
Throws:
IOException - if an error occurs while setting the TTL option value.
Since:
Android 1.0
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
Gets the state of the SocketOptions.IP_MULTICAST_LOOP.

Returns:
true if the IP multicast loop is enabled, false otherwise.
Throws:
SocketException - if the socket is closed or the option is invalid.
Since:
Android 1.0

setLoopbackMode

public void setLoopbackMode(boolean loop)
                     throws SocketException
Sets the SocketOptions.IP_MULTICAST_LOOP.

Parameters:
loop - the value for the socket option socket SocketOptions.IP_MULTICAST_LOOP.
Throws:
SocketException - if the socket is closed or the option is invalid.
Since:
Android 1.0

Build 1.1_r1 (from source)

Please submit a feedback, bug or feature