| Modifier and Type | Class and Description |
|---|---|
| private static class | DatagramSocketAdaptor.
Provides access to non-public constants in DatagramSocket. |
| private static class | DatagramSocketAdaptor.
Defines static methods to invoke non-public NetworkInterface methods. |
| Modifier and Type | Field and Description |
|---|---|
| private final DatagramChannelImpl | |
| private InetAddress | |
| private final Object | |
| private NetworkInterface | |
| private volatile int |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| private InetAddress | |
| private NetworkInterface | |
| public void | bind(SocketAddress local)
Overrides java. Binds this DatagramSocket to a specific address and port. |
| private static InetAddress | Returns: the multicast groupChecks a SocketAddress to ensure that it is a multicast address. |
| public void | close()
Overrides java. Implements java. Closes this datagram socket. |
| public void | connect(InetAddress address, int port)
Overrides java. Connects the socket to a remote address for this socket. |
| public void | connect(SocketAddress remote)
Overrides java. Connects this socket to a remote socket address (IP address + port number). |
| private void | |
| pack-priv static DatagramSocket | |
| private NetworkInterface | defaultNetworkInterface()
Returns the default NetworkInterface to use when joining or leaving a multicast group and a network interface is not specified. |
| public void | |
| private boolean | |
| public boolean | |
| public DatagramChannel | getChannel()
Overrides java. Returns the unique |
| public InetAddress | getInetAddress()
Overrides java. Returns the address to which this socket is connected. |
| public InetAddress | getInterface()
Overrides java.
Deprecated
Retrieve the address of the network interface used for multicast packets. |
| private int | |
| public InetAddress | getLocalAddress()
Overrides java. Gets the local address to which the socket is bound. |
| public int | getLocalPort()
Overrides java. Returns the port number on the local host to which this socket is bound. |
| public SocketAddress | getLocalSocketAddress()
Overrides java. Returns the address of the endpoint this socket is bound to. |
| public boolean | getLoopbackMode()
Overrides java.
Deprecated
Get the setting for local loopback of multicast datagrams. |
| public NetworkInterface | getNetworkInterface()
Overrides java. Get the multicast network interface set for outgoing multicast datagrams sent from this socket. |
| public <T> T | getOption(SocketOption<T> name)
Overrides java. Returns the value of a socket option. |
| public int | getPort()
Overrides java. Returns the port number to which this socket is connected. |
| public int | getReceiveBufferSize()
Overrides java. Get value of the SO_RCVBUF option for this |
| public SocketAddress | getRemoteSocketAddress()
Overrides java. Returns the address of the endpoint this socket is connected to, or
|
| public boolean | getReuseAddress()
Overrides java. Tests if SO_REUSEADDR is enabled. |
| public int | getSendBufferSize()
Overrides java. Get value of the SO_SNDBUF option for this |
| public int | |
| public int | getTimeToLive()
Overrides java. Get the default time-to-live for multicast packets sent out on the socket. |
| public int | getTrafficClass()
Overrides java. Gets traffic class or type-of-service in the IP datagram header for packets sent from this DatagramSocket. |
| public boolean | |
| public boolean | |
| public boolean | isConnected()
Overrides java. Returns the connection state of the socket. |
| public void | joinGroup(InetAddress group)
Overrides java.
Deprecated
Joins a multicast group. |
| public void | joinGroup(SocketAddress mcastaddr, NetworkInterface netIf)
Overrides java. Joins a multicast group. |
| public void | leaveGroup(InetAddress group)
Overrides java.
Deprecated
Leave a multicast group. |
| public void | leaveGroup(SocketAddress mcastaddr, NetworkInterface netIf)
Overrides java. Leave a multicast group on a specified local interface. |
| private NetworkInterface | |
| public void | receive(DatagramPacket p)
Overrides java. Receives a datagram packet from this socket. |
| public void | send(DatagramPacket p)
Overrides java. Sends a datagram packet from this socket. |
| private void | |
| public void | setBroadcast(boolean on)
Overrides java. Enable/disable SO_BROADCAST. |
| public void | setInterface(InetAddress inf)
Overrides java.
Deprecated
Set the multicast network interface used by methods whose behavior would be affected by the value of the network interface. |
| private void | |
| public void | setLoopbackMode(boolean disable)
Overrides java.
Deprecated
Disable/Enable local loopback of multicast datagrams. |
| public void | setNetworkInterface(NetworkInterface netIf)
Overrides java. Specify the network interface for outgoing multicast datagrams sent on this socket. |
| public <T> DatagramSocket | setOption(SocketOption<T> name, T value)
Overrides java. Sets the value of a socket option. |
| public void | setReceiveBufferSize(int size)
Overrides java. Sets the SO_RCVBUF option to the specified value for this
|
| public void | setReuseAddress(boolean on)
Overrides java. Enable/disable the SO_REUSEADDR socket option. |
| public void | setSendBufferSize(int size)
Overrides java. Sets the SO_SNDBUF option to the specified value for this
|
| public void | setSoTimeout(int timeout)
Overrides java. Enable/disable SO_TIMEOUT with the specified timeout, in milliseconds. |
| public void | setTimeToLive(int ttl)
Overrides java. Set the default time-to-live for multicast packets sent out
on this |
| public void | setTrafficClass(int tc)
Overrides java. Sets traffic class or type-of-service octet in the IP datagram header for datagrams sent from this DatagramSocket. |
| public Set | supportedOptions()
Overrides java. Returns a set of the socket options supported by this socket. |
| dc | back to summary |
|---|---|
| private final DatagramChannelImpl dc | |
| outgoingInetAddress | back to summary |
|---|---|
| private InetAddress outgoingInetAddress | |
| outgoingInterfaceLock | back to summary |
|---|---|
| private final Object outgoingInterfaceLock | |
| outgoingNetworkInterface | back to summary |
|---|---|
| private NetworkInterface outgoingNetworkInterface | |
| timeout | back to summary |
|---|---|
| private volatile int timeout | |
| DatagramSocketAdaptor | back to summary |
|---|---|
| private DatagramSocketAdaptor(DatagramChannelImpl dc) throws IOException | |
| anyInetAddress | back to summary |
|---|---|
| private InetAddress anyInetAddress() Returns the InetAddress representing anyLocalAddress. | |
| anyNetworkInterface | back to summary |
|---|---|
| private NetworkInterface anyNetworkInterface() Returns the placeholder for "any network interface", its index is 0. | |
| bind | back to summary |
|---|---|
| public void bind(SocketAddress local) throws SocketException Overrides java. Doc from java. Binds this DatagramSocket to a specific address and port.
If the address is
| |
| checkGroup | back to summary |
|---|---|
| private static InetAddress checkGroup(SocketAddress mcastaddr) throws SocketException Checks a SocketAddress to ensure that it is a multicast address.
| |
| close | back to summary |
|---|---|
| public void close() Overrides java. Implements java. Doc from java. Closes this datagram socket.
Any thread currently blocked in 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.
| |
| connect | back to summary |
|---|---|
| public void connect(InetAddress address, int port) Overrides java. Doc from java. 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 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.
| |
| connect | back to summary |
|---|---|
| public void connect(SocketAddress remote) throws SocketException Overrides java. Doc from java. Connects this socket to a remote socket address (IP address + port number). If given an 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.
| |
| connectInternal | back to summary |
|---|---|
| private void connectInternal(SocketAddress remote) throws SocketException | |
| create | back to summary |
|---|---|
| pack-priv static DatagramSocket create(DatagramChannelImpl dc) | |
| defaultNetworkInterface | back to summary |
|---|---|
| private NetworkInterface defaultNetworkInterface() throws SocketException Returns the default NetworkInterface to use when joining or leaving a multicast group and a network interface is not specified. This method will return the outgoing NetworkInterface if set, otherwise the result of NetworkInterface.getDefault(), otherwise a NetworkInterface with index == 0 as a placeholder for "any network interface". | |
| disconnect | back to summary |
|---|---|
| public void disconnect() Overrides java. Doc from java. Disconnects the socket. If the socket is closed or not connected, then this method has no effect.
| |
| getBooleanOption | back to summary |
|---|---|
| private boolean getBooleanOption(SocketOption<Boolean> name) throws SocketException | |
| getBroadcast | back to summary |
|---|---|
| public boolean getBroadcast() throws SocketException Overrides java. Doc from java. Tests if SO_BROADCAST is enabled.
| |
| getChannel | back to summary |
|---|---|
| public DatagramChannel getChannel() Overrides java. Doc from java. Returns the unique A datagram socket will have a channel if, and only if, the channel
itself was created via the
| |
| getInetAddress | back to summary |
|---|---|
| public InetAddress getInetAddress() Overrides java. Doc from java. Returns the address to which this socket is connected. Returns
If the socket was connected prior to being
| |
| getInterface | back to summary |
|---|---|
| public InetAddress getInterface() throws SocketException Overrides java. Doc from java. Deprecated
Retrieve the address of the network interface used for multicast packets.
| |
| getIntOption | back to summary |
|---|---|
| private int getIntOption(SocketOption<Integer> name) throws SocketException | |
| getLocalAddress | back to summary |
|---|---|
| public InetAddress getLocalAddress() Overrides java. Doc from java. Gets the local address to which the socket is bound. If the socket was initially bound to the wildcard address and
is now
| |
| getLocalPort | back to summary |
|---|---|
| public int getLocalPort() Overrides java. Doc from java. Returns the port number on the local host to which this socket is bound.
| |
| getLocalSocketAddress | back to summary |
|---|---|
| public SocketAddress getLocalSocketAddress() Overrides java. Doc from java. Returns the address of the endpoint this socket is bound to. If the socket was initially bound to the wildcard address and
is now
| |
| getLoopbackMode | back to summary |
|---|---|
| public boolean getLoopbackMode() throws SocketException Overrides java. Doc from java. Deprecated
Get the setting for local loopback of multicast datagrams.
| |
| getNetworkInterface | back to summary |
|---|---|
| public NetworkInterface getNetworkInterface() throws SocketException Overrides java. Doc from java. Get the multicast network interface set for outgoing multicast datagrams sent from this socket.
| |
| getOption | back to summary |
|---|---|
| public <T> T getOption(SocketOption<T> name) throws IOException Overrides java. Doc from java. Returns the value of a socket option.
| |
| getPort | back to summary |
|---|---|
| public int getPort() Overrides java. Doc from java. Returns the port number to which this socket is connected.
Returns
If the socket was connected prior to being
| |
| getReceiveBufferSize | back to summary |
|---|---|
| public int getReceiveBufferSize() throws SocketException Overrides java. Doc from java. Get value of the SO_RCVBUF option for this
| |
| getRemoteSocketAddress | back to summary |
|---|---|
| public SocketAddress getRemoteSocketAddress() Overrides java. Doc from java. Returns the address of the endpoint this socket is connected to, or
If the socket was connected prior to being
| |
| getReuseAddress | back to summary |
|---|---|
| public boolean getReuseAddress() throws SocketException Overrides java. Doc from java. Tests if SO_REUSEADDR is enabled.
| |
| getSendBufferSize | back to summary |
|---|---|
| public int getSendBufferSize() throws SocketException Overrides java. Doc from java. Get value of the SO_SNDBUF option for this
| |
| getSoTimeout | back to summary |
|---|---|
| public int getSoTimeout() throws SocketException Overrides java. Doc from java. Retrieve setting for SO_TIMEOUT. 0 returns implies that the option is disabled (i.e., timeout of infinity).
| |
| getTimeToLive | back to summary |
|---|---|
| public int getTimeToLive() throws IOException Overrides java. Doc from java. Get the default time-to-live for multicast packets sent out on the socket.
| |
| getTrafficClass | back to summary |
|---|---|
| public int getTrafficClass() throws SocketException Overrides java. Doc from java. 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
| |
| isBound | back to summary |
|---|---|
| public boolean isBound() Overrides java. Doc from java. Returns the binding state of the socket.
If the socket was bound prior to being
| |
| isClosed | back to summary |
|---|---|
| public boolean isClosed() Overrides java. Doc from java. Returns whether the socket is closed or not.
| |
| isConnected | back to summary |
|---|---|
| public boolean isConnected() Overrides java. Doc from java. Returns the connection state of the socket.
If the socket was connected prior to being
| |
| joinGroup | back to summary |
|---|---|
| public void joinGroup(InetAddress group) throws IOException Overrides java. Doc from java. Deprecated
Joins a multicast group. Its behavior may be affected by
| |
| joinGroup | back to summary |
|---|---|
| public void joinGroup(SocketAddress mcastaddr, NetworkInterface netIf) throws IOException Overrides java. Doc from java. 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.
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
| |
| leaveGroup | back to summary |
|---|---|
| public void leaveGroup(InetAddress group) throws IOException Overrides java. Doc from java. Deprecated
Leave a multicast group. Its behavior may be affected by
| |
| leaveGroup | back to summary |
|---|---|
| public void leaveGroup(SocketAddress mcastaddr, NetworkInterface netIf) throws IOException Overrides java. Doc from java. Leave a multicast group on a specified local interface.
| |
| outgoingNetworkInterface | back to summary |
|---|---|
| private NetworkInterface outgoingNetworkInterface() throws SocketException Returns the outgoing NetworkInterface or null if not set. | |
| receive | back to summary |
|---|---|
| public void receive(DatagramPacket p) throws IOException Overrides java. Doc from java. Receives a datagram packet from this socket. This method blocks until a
datagram is received.
When this method returns, the This method is interruptible in the following circumstances:
| |
| send | back to summary |
|---|---|
| public void send(DatagramPacket p) throws IOException Overrides java. Doc from java. Sends a datagram packet from this socket. The
| |
| setBooleanOption | back to summary |
|---|---|
| private void setBooleanOption(SocketOption<Boolean> name, boolean value) throws SocketException | |
| setBroadcast | back to summary |
|---|---|
| public void setBroadcast(boolean on) throws SocketException Overrides java. Doc from java. 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.
| |
| setInterface | back to summary |
|---|---|
| public void setInterface(InetAddress inf) throws SocketException Overrides java. Doc from java. 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.
| |
| setIntOption | back to summary |
|---|---|
| private void setIntOption(SocketOption<Integer> name, int value) throws SocketException | |
| setLoopbackMode | back to summary |
|---|---|
| public void setLoopbackMode(boolean disable) throws SocketException Overrides java. Doc from java. 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
| |
| setNetworkInterface | back to summary |
|---|---|
| public void setNetworkInterface(NetworkInterface netIf) throws SocketException Overrides java. Doc from java. Specify the network interface for outgoing multicast datagrams sent on this socket.
| |
| setOption | back to summary |
|---|---|
| public <T> DatagramSocket setOption(SocketOption<T> name, T value) throws IOException Overrides java. Doc from java. Sets the value of a socket option.
| |
| setReceiveBufferSize | back to summary |
|---|---|
| public void setReceiveBufferSize(int size) throws SocketException Overrides java. Doc from java. Sets the SO_RCVBUF option to the specified value for this
Because SO_RCVBUF is a hint, applications that want to
verify what size the buffers were set to should call
Increasing SO_RCVBUF may allow the network implementation
to buffer multiple packets when packets arrive faster than
are being received using Note It is implementation specific if a packet larger than SO_RCVBUF can be received.
| |
| setReuseAddress | back to summary |
|---|---|
| public void setReuseAddress(boolean on) throws SocketException Overrides java. Doc from java. 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 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
When a
The behaviour when
| |
| setSendBufferSize | back to summary |
|---|---|
| public void setSendBufferSize(int size) throws SocketException Overrides java. Doc from java. Sets the SO_SNDBUF option to the specified value for this
As SO_SNDBUF is a hint, applications that want to verify
what size the buffer is should call Increasing the buffer size may allow multiple outgoing packets to be queued by the network implementation when the send rate is high. Note If
| |
| setSoTimeout | back to summary |
|---|---|
| public void setSoTimeout(int timeout) throws SocketException Overrides java. Doc from java. 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.
| |
| setTimeToLive | back to summary |
|---|---|
| public void setTimeToLive(int ttl) throws IOException Overrides java. Doc from java. Set the default time-to-live for multicast packets sent out
on this The ttl must be in the range
| |
| setTrafficClass | back to summary |
|---|---|
| public void setTrafficClass(int tc) throws SocketException Overrides java. Doc from java. 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 Notes For Internet Protocol v4 the value consists of an
Setting bits in the precedence field may result in a SocketException indicating that the operation is not permitted.
for Internet Protocol v6
| |
| supportedOptions | back to summary |
|---|---|
| public Set Overrides java. Doc from java. 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.
| |
| Modifier and Type | Field and Description |
|---|---|
| private static final SocketAddress |
| Access | Constructor and Description |
|---|---|
| private |
| NO_DELEGATE | back to summary |
|---|---|
| private static final SocketAddress NO_DELEGATE | |
| DatagramSockets | back to summary |
|---|---|
| private DatagramSockets() | |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv static final MethodHandle | |
| pack-priv static final MethodHandle |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv static NetworkInterface | |
| pack-priv static NetworkInterface | newNetworkInterface(String name, int index, InetAddress[] addrs)
Creates a NetworkInterface with the given name index and addresses. |
| CONSTRUCTOR | back to summary |
|---|---|
| pack-priv static final MethodHandle CONSTRUCTOR | |
| GET_DEFAULT | back to summary |
|---|---|
| pack-priv static final MethodHandle GET_DEFAULT | |
| NetworkInterfaces | back to summary |
|---|---|
| private NetworkInterfaces() | |
| getDefault | back to summary |
|---|---|
| pack-priv static NetworkInterface getDefault() Returns the default network interface or null. | |
| newNetworkInterface | back to summary |
|---|---|
| pack-priv static NetworkInterface newNetworkInterface(String name, int index, InetAddress[] addrs) Creates a NetworkInterface with the given name index and addresses. | |