MulticastSocket - JRE Emulation | JRE Emulation
public class

MulticastSocket

extends DatagramSocket
java.lang.Object
   ↳ java.net.DatagramSocket
     ↳ java.net.MulticastSocket

Class Overview

This class implements a multicast socket for sending and receiving IP multicast datagram packets.

See Also

Summary

Public Constructors
MulticastSocket()
Constructs a multicast socket, bound to any available port on the local host.
MulticastSocket(int port)
Constructs a multicast socket, bound to the specified port on the local host.
MulticastSocket(SocketAddress localAddress)
Constructs a MulticastSocket bound to the address and port specified by localAddress, or an unbound MulticastSocket if localAddress == null.
Public Methods
InetAddress getInterface()
Returns an address of the outgoing network interface used by this socket.
boolean getLoopbackMode()
Returns true if multicast loopback is disabled.
NetworkInterface getNetworkInterface()
Returns the outgoing network interface used by this socket.
byte getTTL()
This method is deprecated. Use getTimeToLive() instead.
int getTimeToLive()
Returns the time-to-live (TTL) for multicast packets sent on this socket.
void joinGroup(SocketAddress groupAddress, NetworkInterface netInterface)
Adds this socket to the specified multicast group.
void joinGroup(InetAddress groupAddr)
Adds this socket to the specified multicast group.
void leaveGroup(SocketAddress groupAddress, NetworkInterface netInterface)
Removes this socket from the specified multicast group.
void leaveGroup(InetAddress groupAddr)
Removes this socket from the specified multicast group.
void send(DatagramPacket packet, byte ttl)
This method is deprecated. Use setTimeToLive(int) instead.
void setInterface(InetAddress address)
Sets the outgoing network interface used by this socket.
void setLoopbackMode(boolean disable)
Disables multicast loopback if disable == true.
void setNetworkInterface(NetworkInterface networkInterface)
Sets the outgoing network interface used by this socket to the given networkInterface.
void setTTL(byte ttl)
This method is deprecated. Use setTimeToLive(int) instead.
void setTimeToLive(int ttl)
Sets the time-to-live (TTL) for multicast packets sent on this socket.
Inherited Methods
[Expand]
From class java.net.DatagramSocket
From class java.lang.Object
From interface java.io.Closeable
From interface java.lang.AutoCloseable

Public Constructors

public MulticastSocket ()

Constructs a multicast socket, bound to any available port on the local host.

Throws
IOException if an error occurs.

public MulticastSocket (int port)

Constructs a multicast socket, bound to the specified port on the local host.

Throws
IOException if an error occurs.

public MulticastSocket (SocketAddress localAddress)

Constructs a MulticastSocket bound to the address and port specified by localAddress, or an unbound MulticastSocket if localAddress == null.

Throws
IllegalArgumentException if localAddress is not supported (because it's not an InetSocketAddress, say).
IOException if an error occurs.

Public Methods

public InetAddress getInterface ()

Returns an address of the outgoing network interface used by this socket. To avoid inherent unpredictability, new code should use getNetworkInterface() instead.

Throws
SocketException if an error occurs.

public boolean getLoopbackMode ()

Returns true if multicast loopback is disabled. See IP_MULTICAST_LOOP, and note that the sense of this is the opposite of the underlying Unix IP_MULTICAST_LOOP.

Throws
SocketException if an error occurs.

public NetworkInterface getNetworkInterface ()

Returns the outgoing network interface used by this socket.

Throws
SocketException if an error occurs.

public byte getTTL ()

This method is deprecated.
Use getTimeToLive() instead.

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

Throws
IOException if an error occurs.

public int getTimeToLive ()

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

Throws
IOException if an error occurs.

public void joinGroup (SocketAddress groupAddress, NetworkInterface netInterface)

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.
IllegalArgumentException if no multicast group is specified.

public void joinGroup (InetAddress groupAddr)

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.

public void leaveGroup (SocketAddress groupAddress, NetworkInterface netInterface)

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.
IllegalArgumentException if groupAddress is null.

public void leaveGroup (InetAddress groupAddr)

Removes this socket from the specified multicast group.

Parameters
groupAddr the multicast group to be left.
Throws
NullPointerException if groupAddr is null.
IOException if the specified group address is not a multicast address.

public void send (DatagramPacket packet, byte ttl)

This method is deprecated.
Use setTimeToLive(int) instead.

Sends the given packet on this socket, using the given ttl. This method is deprecated because it modifies the TTL socket option for this socket twice on each call.

Throws
IOException if an error occurs.

public void setInterface (InetAddress address)

Sets the outgoing network interface used by this socket. The interface used is the first interface found to have the given address. To avoid inherent unpredictability, new code should use getNetworkInterface() instead.

Throws
SocketException if an error occurs.

public void setLoopbackMode (boolean disable)

Disables multicast loopback if disable == true. See IP_MULTICAST_LOOP, and note that the sense of this is the opposite of the underlying Unix IP_MULTICAST_LOOP: true means disabled, false means enabled.

Throws
SocketException if an error occurs.

public void setNetworkInterface (NetworkInterface networkInterface)

Sets the outgoing network interface used by this socket to the given networkInterface.

Throws
SocketException if an error occurs.

public void setTTL (byte ttl)

This method is deprecated.
Use setTimeToLive(int) instead.

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

Throws
IOException if an error occurs.

public void setTimeToLive (int ttl)

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

Throws
IOException if an error occurs.