APIdia Launch Partner
Top Description Fields Constructors Methods
java.net

pack-priv final Class NetMulticastSocket

extends MulticastSocket
Class Inheritance
Imports
java.io.IOException, .UncheckedIOException, java.util.Enumeration, .Objects, .Set, .Collections

A multicast datagram socket that delegates socket operations to a DatagramSocketImpl. This class overrides every public method defined by DatagramSocket and MulticastSocket.

Field Summary

Modifier and TypeField and Description
private boolean
bound

Various states of this socket.

private int
private boolean
private final Object
pack-priv InetAddress
pack-priv int
pack-priv int
private volatile boolean
private boolean
explicitFilter

Set when a socket is ST_CONNECTED until we are certain that any packets which might have been received prior to calling connect() but not read by the application have been read.

private final DatagramSocketImpl
private InetAddress
infAddress

The "last" interface set by setInterface on this MulticastSocket

private final Object
infLock

The lock on the socket's interface - used by setInterface and getInterface

private boolean
interfaceSet

Used on some platforms to record if an outgoing interface has been set for this socket.

private volatile Set<SocketOption<?>>
private final Object
pack-priv static final int
pack-priv static final int

Constructor Summary

AccessConstructor and Description
pack-priv
NetMulticastSocket(DatagramSocketImpl
The impl used in this instance.
impl
)

This constructor is also used by DatagramSocket#DatagramSocket(DatagramSocketImpl).

Method Summary

Modifier and TypeMethod and Description
public synchronized void
bind(SocketAddress addr)

Overrides java.net.DatagramSocket.bind.

Binds this DatagramSocket to a specific address and port.

pack-priv static void
private boolean
public void
close()

Overrides java.net.DatagramSocket.close.

Implements java.io.Closeable.close.

Closes this datagram socket.

public void
connect(InetAddress address, int port)

Overrides java.net.DatagramSocket.connect.

Connects the socket to a remote address for this socket.

public void
connect(SocketAddress addr)

Overrides java.net.DatagramSocket.connect.

Connects this socket to a remote socket address (IP address + port number).

private synchronized void
connectInternal(InetAddress
The remote address.
address
,
int
The remote port
port
)

Connects this socket to a remote socket address (IP address + port number).

public void
disconnect()

Overrides java.net.DatagramSocket.disconnect.

Disconnects the socket.

public synchronized boolean
getBroadcast()

Overrides java.net.DatagramSocket.getBroadcast.

Tests if SO_BROADCAST is enabled.

pack-priv final DatagramSocketImpl

Returns:

the DatagramSocketImpl attached to that DatagramSocket
getImpl
()

Return the DatagramSocketImpl attached to this socket, creating the socket if not already created.

public InetAddress
getInetAddress()

Overrides java.net.DatagramSocket.getInetAddress.

Returns the address to which this socket is connected.

public InetAddress
getInterface()

Overrides java.net.MulticastSocket.getInterface.

Deprecated

Retrieve the address of the network interface used for multicast packets.

public InetAddress
getLocalAddress()

Overrides java.net.DatagramSocket.getLocalAddress.

Gets the local address to which the socket is bound.

public int
getLocalPort()

Overrides java.net.DatagramSocket.getLocalPort.

Returns the port number on the local host to which this socket is bound.

public SocketAddress
getLocalSocketAddress()

Overrides java.net.DatagramSocket.getLocalSocketAddress.

Returns the address of the endpoint this socket is bound to.

public boolean
getLoopbackMode()

Overrides java.net.MulticastSocket.getLoopbackMode.

Deprecated

Get the setting for local loopback of multicast datagrams.

public NetworkInterface
getNetworkInterface()

Overrides java.net.MulticastSocket.getNetworkInterface.

Get the multicast network interface set for outgoing multicast datagrams sent from this socket.

public <T> T
getOption(SocketOption<T> name)

Overrides java.net.DatagramSocket.getOption.

Returns the value of a socket option.

public int
getPort()

Overrides java.net.DatagramSocket.getPort.

Returns the port number to which this socket is connected.

public synchronized int
getReceiveBufferSize()

Overrides java.net.DatagramSocket.getReceiveBufferSize.

Get value of the SO_RCVBUF option for this DatagramSocket, that is the buffer size, in bytes, used by the platform for input on this DatagramSocket.

public SocketAddress
getRemoteSocketAddress()

Overrides java.net.DatagramSocket.getRemoteSocketAddress.

Returns the address of the endpoint this socket is connected to, or null if it is unconnected.

public synchronized boolean
getReuseAddress()

Overrides java.net.DatagramSocket.getReuseAddress.

Tests if SO_REUSEADDR is enabled.

public synchronized int
getSendBufferSize()

Overrides java.net.DatagramSocket.getSendBufferSize.

Get value of the SO_SNDBUF option for this DatagramSocket, that is the buffer size, in bytes, used by the platform for output on this DatagramSocket.

public synchronized int
getSoTimeout()

Overrides java.net.DatagramSocket.getSoTimeout.

Retrieve setting for SO_TIMEOUT.

public int
getTimeToLive()

Overrides java.net.MulticastSocket.getTimeToLive.

Get the default time-to-live for multicast packets sent out on the socket.

public synchronized int
getTrafficClass()

Overrides java.net.DatagramSocket.getTrafficClass.

Gets traffic class or type-of-service in the IP datagram header for packets sent from this DatagramSocket.

public boolean
isBound()

Overrides java.net.DatagramSocket.isBound.

Returns the binding state of the socket.

public boolean
isClosed()

Overrides java.net.DatagramSocket.isClosed.

Returns whether the socket is closed or not.

public boolean
isConnected()

Overrides java.net.DatagramSocket.isConnected.

Returns the connection state of the socket.

public void
joinGroup(InetAddress mcastaddr)

Overrides java.net.MulticastSocket.joinGroup.

Deprecated

Joins a multicast group.

public void
joinGroup(SocketAddress mcastaddr, NetworkInterface netIf)

Overrides java.net.MulticastSocket.joinGroup.

Joins a multicast group.

public void
leaveGroup(InetAddress mcastaddr)

Overrides java.net.MulticastSocket.leaveGroup.

Deprecated

Leave a multicast group.

public void
leaveGroup(SocketAddress mcastaddr, NetworkInterface netIf)

Overrides java.net.MulticastSocket.leaveGroup.

Leave a multicast group on a specified local interface.

public synchronized void
receive(DatagramPacket p)

Overrides java.net.DatagramSocket.receive.

Receives a datagram packet from this socket.

public void
send(DatagramPacket p)

Overrides java.net.DatagramSocket.send.

Sends a datagram packet from this socket.

public synchronized void
setBroadcast(boolean on)

Overrides java.net.DatagramSocket.setBroadcast.

Enable/disable SO_BROADCAST.

public void
setInterface(InetAddress inf)

Overrides java.net.MulticastSocket.setInterface.

Deprecated

Set the multicast network interface used by methods whose behavior would be affected by the value of the network interface.

public void
setLoopbackMode(boolean disable)

Overrides java.net.MulticastSocket.setLoopbackMode.

Deprecated

Disable/Enable local loopback of multicast datagrams.

public void
setNetworkInterface(NetworkInterface netIf)

Overrides java.net.MulticastSocket.setNetworkInterface.

Specify the network interface for outgoing multicast datagrams sent on this socket.

public <T> DatagramSocket
setOption(SocketOption<T> name, T value)

Overrides java.net.DatagramSocket.setOption.

Sets the value of a socket option.

public synchronized void
setReceiveBufferSize(int size)

Overrides java.net.DatagramSocket.setReceiveBufferSize.

Sets the SO_RCVBUF option to the specified value for this DatagramSocket.

public synchronized void
setReuseAddress(boolean on)

Overrides java.net.DatagramSocket.setReuseAddress.

Enable/disable the SO_REUSEADDR socket option.

public synchronized void
setSendBufferSize(int size)

Overrides java.net.DatagramSocket.setSendBufferSize.

Sets the SO_SNDBUF option to the specified value for this DatagramSocket.

public synchronized void
setSoTimeout(int timeout)

Overrides java.net.DatagramSocket.setSoTimeout.

Enable/disable SO_TIMEOUT with the specified timeout, in milliseconds.

public void
setTimeToLive(int ttl)

Overrides java.net.MulticastSocket.setTimeToLive.

Set the default time-to-live for multicast packets sent out on this MulticastSocket in order to control the scope of the multicasts.

public synchronized void
setTrafficClass(int tc)

Overrides java.net.DatagramSocket.setTrafficClass.

Sets traffic class or type-of-service octet in the IP datagram header for datagrams sent from this DatagramSocket.

public Set<SocketOption<?>>
supportedOptions()

Overrides java.net.DatagramSocket.supportedOptions.

Returns a set of the socket options supported by this socket.

Inherited from java.net.MulticastSocket:
delegate

Field Detail

boundback to summary
private boolean bound

Various states of this socket.

bytesLeftToFilterback to summary
private int bytesLeftToFilter
closedback to summary
private boolean closed
closeLockback to summary
private final Object closeLock
connectedAddressback to summary
pack-priv InetAddress connectedAddress
connectedPortback to summary
pack-priv int connectedPort
connectStateback to summary
pack-priv int connectState
createdback to summary
private volatile boolean created
explicitFilterback to summary
private boolean explicitFilter

Set when a socket is ST_CONNECTED until we are certain that any packets which might have been received prior to calling connect() but not read by the application have been read. During this time we check the source address of all packets received to be sure they are from the connected destination. Other packets are read but silently dropped.

implback to summary
private final DatagramSocketImpl impl
infAddressback to summary
private InetAddress infAddress

The "last" interface set by setInterface on this MulticastSocket

infLockback to summary
private final Object infLock

The lock on the socket's interface - used by setInterface and getInterface

interfaceSetback to summary
private boolean interfaceSet

Used on some platforms to record if an outgoing interface has been set for this socket.

optionsback to summary
private volatile Set<SocketOption<?>> options
optionsLockback to summary
private final Object optionsLock
ST_CONNECTEDback to summary
pack-priv static final int ST_CONNECTED
ST_NOT_CONNECTEDback to summary
pack-priv static final int ST_NOT_CONNECTED

Constructor Detail

NetMulticastSocketback to summary
pack-priv NetMulticastSocket(DatagramSocketImpl impl)

This constructor is also used by DatagramSocket#DatagramSocket(DatagramSocketImpl).

Parameters
impl:DatagramSocketImpl

The impl used in this instance.

Method Detail

bindback to summary
public synchronized void bind(SocketAddress addr) throws SocketException

Overrides java.net.DatagramSocket.bind.

Doc from java.net.DatagramSocket.bind.

Binds this DatagramSocket to a specific address and port.

If the address is null, then the system will pick up an ephemeral port and a valid local address to bind the socket.

Annotations
@Override
Exceptions
SocketException:
if any error happens during the bind, or if the socket is already bound or is closed.
checkAddressback to summary
pack-priv static void checkAddress(InetAddress addr, String op)
checkFilteringback to summary
private boolean checkFiltering(DatagramPacket p) throws SocketException
closeback to summary
public void close()

Overrides java.net.DatagramSocket.close.

Implements java.io.Closeable.close.

Doc from java.net.DatagramSocket.close.

Closes this datagram socket.

Any thread currently blocked in receive upon this socket will throw a SocketException.

If this socket has an associated channel then the channel is closed as well.

Once closed, several of the methods defined by this class will throw an exception if invoked on the closed socket.

Annotations
@Override
connectback to summary
public void connect(InetAddress address, int port)

Overrides java.net.DatagramSocket.connect.

Doc from java.net.DatagramSocket.connect.

Connects the socket to a remote address for this socket. When a socket is connected to a remote address, packets may only be sent to or received from that address. By default a datagram socket is not connected. If the socket is already closed, then this method has no effect.

If this socket is not bound then this method will first cause the socket to be bound to an address that is assigned automatically, as if invoking the bind method with a parameter of null. If the remote destination to which the socket is connected does not exist, or is otherwise unreachable, and if an ICMP destination unreachable packet has been received for that address, then a subsequent call to send or receive may throw a PortUnreachableException. Note, there is no guarantee that the exception will be thrown.

If this socket is already connected, then this method will attempt to connect to the given address. If this connect fails then the state of this socket is unknown - it may or may not be connected to the address that it was previously connected to.

When the socket is connected, the send method checks that the packet's address matches the remote address that the socket is connected to. A socket connected to a multicast address may only be used to send packets. Datagrams in the socket's socket receive buffer, which have not been received before invoking this method, may be discarded.

Annotations
@Override
connectback to summary
public void connect(SocketAddress addr) throws SocketException

Overrides java.net.DatagramSocket.connect.

Doc from java.net.DatagramSocket.connect.

Connects this socket to a remote socket address (IP address + port number).

If given an InetSocketAddress, this method behaves as if invoking connect(InetAddress,int) with the given socket addresses IP address and port number, except that the SocketException that may be raised is not wrapped in an UncheckedIOException. Datagrams in the socket's socket receive buffer, which have not been received before invoking this method, may be discarded.

If this socket is already connected, then this method will attempt to connect to the given address. If this connect fails then the state of this socket is unknown - it may or may not be connected to the address that it was previously connected to.

Annotations
@Override
Exceptions
SocketException:
if the connect fails
connectInternalback to summary
private synchronized void connectInternal(InetAddress address, int port) throws SocketException

Connects this socket to a remote socket address (IP address + port number). Binds socket if not already bound.

Parameters
address:InetAddress

The remote address.

port:int

The remote port

Exceptions
SocketException:
if binding the socket fails.
disconnectback to summary
public void disconnect()

Overrides java.net.DatagramSocket.disconnect.

Doc from java.net.DatagramSocket.disconnect.

Disconnects the socket. If the socket is closed or not connected, then this method has no effect.

Annotations
@Override
getBroadcastback to summary
public synchronized boolean getBroadcast() throws SocketException

Overrides java.net.DatagramSocket.getBroadcast.

Doc from java.net.DatagramSocket.getBroadcast.

Tests if SO_BROADCAST is enabled.

Annotations
@Override
Exceptions
SocketException:
if there is an error in the underlying protocol, such as an UDP error, or the socket is closed.
getImplback to summary
pack-priv final DatagramSocketImpl getImpl() throws SocketException

Return the DatagramSocketImpl attached to this socket, creating the socket if not already created.

Returns:DatagramSocketImpl

the DatagramSocketImpl attached to that DatagramSocket

Exceptions
SocketException:
if creating the socket fails
Since
1.4
getInetAddressback to summary
public InetAddress getInetAddress()

Overrides java.net.DatagramSocket.getInetAddress.

Doc from java.net.DatagramSocket.getInetAddress.

Returns the address to which this socket is connected. Returns null if the socket is not connected.

If the socket was connected prior to being closed, then this method will continue to return the connected address after the socket is closed.

Annotations
@Override
getInterfaceback to summary
public InetAddress getInterface() throws SocketException

Overrides java.net.MulticastSocket.getInterface.

Doc from java.net.MulticastSocket.getInterface.

Deprecated

Retrieve the address of the network interface used for multicast packets.

Annotations
@Override
@Deprecated
Exceptions
SocketException:
if there is an error in the underlying protocol, such as a TCP error, or the socket is closed.
getLocalAddressback to summary
public InetAddress getLocalAddress()

Overrides java.net.DatagramSocket.getLocalAddress.

Doc from java.net.DatagramSocket.getLocalAddress.

Gets the local address to which the socket is bound.

If the socket was initially bound to the wildcard address and is now connected, then the address returned may be the local address selected as the source address for datagrams sent on the socket instead of the wildcard address. When disconnect() is called, the bound address reverts to the wildcard address.

Annotations
@Override
getLocalPortback to summary
public int getLocalPort()

Overrides java.net.DatagramSocket.getLocalPort.

Doc from java.net.DatagramSocket.getLocalPort.

Returns the port number on the local host to which this socket is bound.

Annotations
@Override
getLocalSocketAddressback to summary
public SocketAddress getLocalSocketAddress()

Overrides java.net.DatagramSocket.getLocalSocketAddress.

Doc from java.net.DatagramSocket.getLocalSocketAddress.

Returns the address of the endpoint this socket is bound to.

If the socket was initially bound to the wildcard address and is now connected, then the address returned may be the local address selected as the source address for datagrams sent on this socket instead of the wildcard address. When disconnect() is called, the bound address reverts to the wildcard address.

Annotations
@Override
getLoopbackModeback to summary
public boolean getLoopbackMode() throws SocketException

Overrides java.net.MulticastSocket.getLoopbackMode.

Doc from java.net.MulticastSocket.getLoopbackMode.

Deprecated

Get the setting for local loopback of multicast datagrams.

Annotations
@Override
@Deprecated
Exceptions
SocketException:
if an error occurs while getting the value, or the socket is closed.
getNetworkInterfaceback to summary
public NetworkInterface getNetworkInterface() throws SocketException

Overrides java.net.MulticastSocket.getNetworkInterface.

Doc from java.net.MulticastSocket.getNetworkInterface.

Get the multicast network interface set for outgoing multicast datagrams sent from this socket.

Annotations
@Override
Exceptions
SocketException:
if there is an error in the underlying protocol, such as a TCP error, or the socket is closed.
getOptionback to summary
public <T> T getOption(SocketOption<T> name) throws IOException

Overrides java.net.DatagramSocket.getOption.

Doc from java.net.DatagramSocket.getOption.

Returns the value of a socket option.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs, or if the socket is closed.
getPortback to summary
public int getPort()

Overrides java.net.DatagramSocket.getPort.

Doc from java.net.DatagramSocket.getPort.

Returns the port number to which this socket is connected. Returns -1 if the socket is not connected.

If the socket was connected prior to being closed, then this method will continue to return the connected port number after the socket is closed.

Annotations
@Override
getReceiveBufferSizeback to summary
public synchronized int getReceiveBufferSize() throws SocketException

Overrides java.net.DatagramSocket.getReceiveBufferSize.

Doc from java.net.DatagramSocket.getReceiveBufferSize.

Get value of the SO_RCVBUF option for this DatagramSocket, that is the buffer size, in bytes, used by the platform for input on this DatagramSocket.

Annotations
@Override
Exceptions
SocketException:
if there is an error in the underlying protocol, such as an UDP error, or the socket is closed.
getRemoteSocketAddressback to summary
public SocketAddress getRemoteSocketAddress()

Overrides java.net.DatagramSocket.getRemoteSocketAddress.

Doc from java.net.DatagramSocket.getRemoteSocketAddress.

Returns the address of the endpoint this socket is connected to, or null if it is unconnected.

If the socket was connected prior to being closed, then this method will continue to return the connected address after the socket is closed.

Annotations
@Override
getReuseAddressback to summary
public synchronized boolean getReuseAddress() throws SocketException

Overrides java.net.DatagramSocket.getReuseAddress.

Doc from java.net.DatagramSocket.getReuseAddress.

Tests if SO_REUSEADDR is enabled.

Annotations
@Override
Exceptions
SocketException:
if there is an error in the underlying protocol, such as an UDP error, or the socket is closed.
getSendBufferSizeback to summary
public synchronized int getSendBufferSize() throws SocketException

Overrides java.net.DatagramSocket.getSendBufferSize.

Doc from java.net.DatagramSocket.getSendBufferSize.

Get value of the SO_SNDBUF option for this DatagramSocket, that is the buffer size, in bytes, used by the platform for output on this DatagramSocket.

Annotations
@Override
Exceptions
SocketException:
if there is an error in the underlying protocol, such as an UDP error, or the socket is closed.
getSoTimeoutback to summary
public synchronized int getSoTimeout() throws SocketException

Overrides java.net.DatagramSocket.getSoTimeout.

Doc from java.net.DatagramSocket.getSoTimeout.

Retrieve setting for SO_TIMEOUT. 0 returns implies that the option is disabled (i.e., timeout of infinity).

Annotations
@Override
Exceptions
SocketException:
if there is an error in the underlying protocol, such as an UDP error, or the socket is closed.
getTimeToLiveback to summary
public int getTimeToLive() throws IOException

Overrides java.net.MulticastSocket.getTimeToLive.

Doc from java.net.MulticastSocket.getTimeToLive.

Get the default time-to-live for multicast packets sent out on the socket.

Annotations
@Override
Exceptions
IOException:
if an I/O exception occurs while getting the default time-to-live value, or the socket is closed.
getTrafficClassback to summary
public synchronized int getTrafficClass() throws SocketException

Overrides java.net.DatagramSocket.getTrafficClass.

Doc from java.net.DatagramSocket.getTrafficClass.

Gets traffic class or type-of-service in the IP datagram header for packets sent from this DatagramSocket.

As the underlying network implementation may ignore the traffic class or type-of-service set using setTrafficClass(int) this method may return a different value than was previously set using the setTrafficClass(int) method on this DatagramSocket.

Annotations
@Override
Exceptions
SocketException:
if there is an error obtaining the traffic class or type-of-service value, or the socket is closed.
isBoundback to summary
public boolean isBound()

Overrides java.net.DatagramSocket.isBound.

Doc from java.net.DatagramSocket.isBound.

Returns the binding state of the socket.

If the socket was bound prior to being closed, then this method will continue to return true after the socket is closed.

Annotations
@Override
isClosedback to summary
public boolean isClosed()

Overrides java.net.DatagramSocket.isClosed.

Doc from java.net.DatagramSocket.isClosed.

Returns whether the socket is closed or not.

Annotations
@Override
isConnectedback to summary
public boolean isConnected()

Overrides java.net.DatagramSocket.isConnected.

Doc from java.net.DatagramSocket.isConnected.

Returns the connection state of the socket.

If the socket was connected prior to being closed, then this method will continue to return true after the socket is closed.

Annotations
@Override
joinGroupback to summary
public void joinGroup(InetAddress mcastaddr) throws IOException

Overrides java.net.MulticastSocket.joinGroup.

Doc from java.net.MulticastSocket.joinGroup.

Deprecated

Joins a multicast group. Its behavior may be affected by setInterface or setNetworkInterface.

Annotations
@Override
@Deprecated
Exceptions
IOException:
if there is an error joining, or when the address is not a multicast address, or the platform does not support multicasting, or the socket is closed.
joinGroupback to summary
public void joinGroup(SocketAddress mcastaddr, NetworkInterface netIf) throws IOException

Overrides java.net.MulticastSocket.joinGroup.

Doc from java.net.MulticastSocket.joinGroup.

Joins a multicast group.

In order to join a multicast group, the caller should specify the IP address of the multicast group to join, and the local network interface to receive multicast packets from.

  • The mcastaddr argument indicates the IP address of the multicast group to join. For historical reasons this is specified as a SocketAddress. The default implementation only supports InetSocketAddress and the port information is ignored.
  • The netIf argument specifies the local interface to receive multicast datagram packets, or null to defer to the interface set for outgoing multicast datagrams. If null, and no interface has been set, the behaviour is unspecified: any interface may be selected or the operation may fail with a SocketException.

It is possible to call this method several times to join several different multicast groups, or join the same group in several different networks. However, if the socket is already a member of the group, an IOException will be thrown.

Annotations
@Override
Exceptions
IOException:
if there is an error joining, or when the address is not a multicast address, or the platform does not support multicasting, or the socket is closed
leaveGroupback to summary
public void leaveGroup(InetAddress mcastaddr) throws IOException

Overrides java.net.MulticastSocket.leaveGroup.

Doc from java.net.MulticastSocket.leaveGroup.

Deprecated

Leave a multicast group. Its behavior may be affected by setInterface or setNetworkInterface.

Annotations
@Override
@Deprecated
Exceptions
IOException:
if there is an error leaving or when the address is not a multicast address, or the socket is closed.
leaveGroupback to summary
public void leaveGroup(SocketAddress mcastaddr, NetworkInterface netIf) throws IOException

Overrides java.net.MulticastSocket.leaveGroup.

Doc from java.net.MulticastSocket.leaveGroup.

Leave a multicast group on a specified local interface.

Annotations
@Override
Exceptions
IOException:
if there is an error leaving or when the address is not a multicast address, or the socket is closed.
receiveback to summary
public synchronized void receive(DatagramPacket p) throws IOException

Overrides java.net.DatagramSocket.receive.

Doc from java.net.DatagramSocket.receive.

Receives a datagram packet from this socket. This method blocks until a datagram is received. When this method returns, the DatagramPacket's buffer is filled with the data received. The datagram packet also contains the sender's IP address, and the port number on the sender's machine. The length field of the datagram packet object contains the length of the received message. If the message is longer than the packet's length, the message is truncated.

This method is interruptible in the following circumstances:

  1. The datagram socket is associated with a DatagramChannel. In that case, interrupting a thread receiving a datagram packet will close the underlying channel and cause this method to throw java.nio.channels.ClosedByInterruptException with the thread's interrupted status set.
  2. The datagram socket uses the system-default socket implementation and a virtual thread is receiving a datagram packet. In that case, interrupting the virtual thread will cause it to wakeup and close the socket. This method will then throw SocketException with the thread's interrupted status set.
Annotations
@Override
Exceptions
IOException:
if an I/O error occurs, or the socket is closed.
sendback to summary
public void send(DatagramPacket p) throws IOException

Overrides java.net.DatagramSocket.send.

Doc from java.net.DatagramSocket.send.

Sends a datagram packet from this socket. The DatagramPacket includes information indicating the data to be sent, its length, the IP address of the remote host, and the port number on the remote host.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs, or the socket is closed.
setBroadcastback to summary
public synchronized void setBroadcast(boolean on) throws SocketException

Overrides java.net.DatagramSocket.setBroadcast.

Doc from java.net.DatagramSocket.setBroadcast.

Enable/disable SO_BROADCAST.

Some operating systems may require that the Java virtual machine be started with implementation specific privileges to enable this option or send broadcast datagrams.

Annotations
@Override
Exceptions
SocketException:
if there is an error in the underlying protocol, such as an UDP error, or the socket is closed.
setInterfaceback to summary
public void setInterface(InetAddress inf) throws SocketException

Overrides java.net.MulticastSocket.setInterface.

Doc from java.net.MulticastSocket.setInterface.

Deprecated

Set the multicast network interface used by methods whose behavior would be affected by the value of the network interface. Useful for multihomed hosts.

Annotations
@Override
@Deprecated
Exceptions
SocketException:
if there is an error in the underlying protocol, such as a TCP error, or the socket is closed.
setLoopbackModeback to summary
public void setLoopbackMode(boolean disable) throws SocketException

Overrides java.net.MulticastSocket.setLoopbackMode.

Doc from java.net.MulticastSocket.setLoopbackMode.

Deprecated

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()

Annotations
@Override
@Deprecated
Exceptions
SocketException:
if an error occurs while setting the value, or the socket is closed.
setNetworkInterfaceback to summary
public void setNetworkInterface(NetworkInterface netIf) throws SocketException

Overrides java.net.MulticastSocket.setNetworkInterface.

Doc from java.net.MulticastSocket.setNetworkInterface.

Specify the network interface for outgoing multicast datagrams sent on this socket.

Annotations
@Override
Exceptions
SocketException:
if there is an error in the underlying protocol, such as a TCP error, or the socket is closed.
setOptionback to summary
public <T> DatagramSocket setOption(SocketOption<T> name, T value) throws IOException

Overrides java.net.DatagramSocket.setOption.

Doc from java.net.DatagramSocket.setOption.

Sets the value of a socket option.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs, or if the socket is closed.
setReceiveBufferSizeback to summary
public synchronized void setReceiveBufferSize(int size) throws SocketException

Overrides java.net.DatagramSocket.setReceiveBufferSize.

Doc from java.net.DatagramSocket.setReceiveBufferSize.

Sets the SO_RCVBUF option to the specified value for this DatagramSocket. The SO_RCVBUF option is used by the network implementation as a hint to size the underlying network I/O buffers. The SO_RCVBUF setting may also be used by the network implementation to determine the maximum size of the packet that can be received on this socket.

Because SO_RCVBUF is a hint, applications that want to verify what size the buffers were set to should call getReceiveBufferSize().

Increasing SO_RCVBUF may allow the network implementation to buffer multiple packets when packets arrive faster than are being received using receive(DatagramPacket).

Note

It is implementation specific if a packet larger than SO_RCVBUF can be received.

Annotations
@Override
Exceptions
SocketException:
if there is an error in the underlying protocol, such as an UDP error, or the socket is closed.
setReuseAddressback to summary
public synchronized void setReuseAddress(boolean on) throws SocketException

Overrides java.net.DatagramSocket.setReuseAddress.

Doc from java.net.DatagramSocket.setReuseAddress.

Enable/disable the SO_REUSEADDR socket option.

For UDP sockets it may be necessary to bind more than one socket to the same socket address. This is typically for the purpose of receiving multicast packets (See java.net.MulticastSocket). The SO_REUSEADDR socket option allows multiple sockets to be bound to the same socket address if the SO_REUSEADDR socket option is enabled prior to binding the socket using bind(SocketAddress).

Note

This functionality is not supported by all existing platforms, so it is implementation specific whether this option will be ignored or not. However, if it is not supported then getReuseAddress() will always return false.

When a DatagramSocket is created the initial setting of SO_REUSEADDR is disabled.

The behaviour when SO_REUSEADDR is enabled or disabled after a socket is bound (See isBound()) is not defined.

Annotations
@Override
Exceptions
SocketException:
if an error occurs enabling or disabling the SO_REUSEADDR socket option, or the socket is closed.
setSendBufferSizeback to summary
public synchronized void setSendBufferSize(int size) throws SocketException

Overrides java.net.DatagramSocket.setSendBufferSize.

Doc from java.net.DatagramSocket.setSendBufferSize.

Sets the SO_SNDBUF option to the specified value for this DatagramSocket. The SO_SNDBUF option is used by the network implementation as a hint to size the underlying network I/O buffers. The SO_SNDBUF setting may also be used by the network implementation to determine the maximum size of the packet that can be sent on this socket.

As SO_SNDBUF is a hint, applications that want to verify what size the buffer is should call getSendBufferSize().

Increasing the buffer size may allow multiple outgoing packets to be queued by the network implementation when the send rate is high.

Note

If send(DatagramPacket) is used to send a DatagramPacket that is larger than the setting of SO_SNDBUF then it is implementation specific if the packet is sent or discarded.

Annotations
@Override
Exceptions
SocketException:
if there is an error in the underlying protocol, such as an UDP error, or the socket is closed.
setSoTimeoutback to summary
public synchronized void setSoTimeout(int timeout) throws SocketException

Overrides java.net.DatagramSocket.setSoTimeout.

Doc from java.net.DatagramSocket.setSoTimeout.

Enable/disable SO_TIMEOUT with the specified timeout, in milliseconds. With this option set to a positive timeout value, a call to receive() for this DatagramSocket will block for only this amount of time. If the timeout expires, a java.net.SocketTimeoutException is raised, though the DatagramSocket is still valid. A timeout of zero is interpreted as an infinite timeout. The option must be enabled prior to entering the blocking operation to have effect.

Annotations
@Override
Exceptions
SocketException:
if there is an error in the underlying protocol, such as an UDP error, or the socket is closed.
setTimeToLiveback to summary
public void setTimeToLive(int ttl) throws IOException

Overrides java.net.MulticastSocket.setTimeToLive.

Doc from java.net.MulticastSocket.setTimeToLive.

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. Multicast packets sent with a TTL of 0 are not transmitted on the network but may be delivered locally.

Annotations
@Override
Exceptions
IOException:
if an I/O exception occurs while setting the default time-to-live value, or the socket is closed.
setTrafficClassback to summary
public synchronized void setTrafficClass(int tc) throws SocketException

Overrides java.net.DatagramSocket.setTrafficClass.

Doc from java.net.DatagramSocket.setTrafficClass.

Sets traffic class or type-of-service octet in the IP datagram header for datagrams sent from this DatagramSocket. As the underlying network implementation may ignore this value applications should consider it a hint.

The tc must be in the range 0 <= tc <= 255 or an IllegalArgumentException will be thrown.

Notes

For Internet Protocol v4 the value consists of an integer, the least significant 8 bits of which represent the value of the TOS octet in IP packets sent by the socket. RFC 1349 defines the TOS values as follows:

  • IPTOS_LOWCOST (0x02)
  • IPTOS_RELIABILITY (0x04)
  • IPTOS_THROUGHPUT (0x08)
  • IPTOS_LOWDELAY (0x10)
The last low order bit is always ignored as this corresponds to the MBZ (must be zero) bit.

Setting bits in the precedence field may result in a SocketException indicating that the operation is not permitted.

for Internet Protocol v6 tc is the value that would be placed into the sin6_flowinfo field of the IP header.

Annotations
@Override
Exceptions
SocketException:
if there is an error setting the traffic class or type-of-service, or the socket is closed.
supportedOptionsback to summary
public Set<SocketOption<?>> supportedOptions()

Overrides java.net.DatagramSocket.supportedOptions.

Doc from java.net.DatagramSocket.supportedOptions.

Returns a set of the socket options supported by this socket. This method will continue to return the set of options even after the socket has been closed.

Annotations
@Override