DatagramSocketImpl.
This class overrides every public method defined by DatagramSocket
and MulticastSocket.
| Modifier and Type | Field 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 | |
| private final Object | |
| pack-priv static final int | |
| pack-priv static final int |
| Access | Constructor and Description |
|---|---|
| pack-priv | NetMulticastSocket(DatagramSocketImpl
The impl used in this instance. impl)This constructor is also used by |
| Modifier and Type | Method and Description |
|---|---|
| public synchronized void | bind(SocketAddress addr)
Overrides java. Binds this DatagramSocket to a specific address and port. |
| pack-priv static void | |
| private boolean | |
| 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 addr)
Overrides java. 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 | |
| public synchronized boolean | |
| pack-priv final DatagramSocketImpl | Returns: theDatagramSocketImpl attached to that
DatagramSocketReturn the |
| 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. |
| 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 synchronized 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 synchronized boolean | getReuseAddress()
Overrides java. Tests if SO_REUSEADDR is enabled. |
| public synchronized int | getSendBufferSize()
Overrides java. Get value of the SO_SNDBUF option for this |
| public synchronized int | |
| public int | getTimeToLive()
Overrides java. Get the default time-to-live for multicast packets sent out on the socket. |
| public synchronized 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 mcastaddr)
Overrides java.
Deprecated
Joins a multicast group. |
| public void | joinGroup(SocketAddress mcastaddr, NetworkInterface netIf)
Overrides java. Joins a multicast group. |
| public void | leaveGroup(InetAddress mcastaddr)
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. |
| public synchronized 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. |
| public synchronized 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. |
| 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 synchronized void | setReceiveBufferSize(int size)
Overrides java. Sets the SO_RCVBUF option to the specified value for this
|
| public synchronized void | setReuseAddress(boolean on)
Overrides java. Enable/disable the SO_REUSEADDR socket option. |
| public synchronized void | setSendBufferSize(int size)
Overrides java. Sets the SO_SNDBUF option to the specified value for this
|
| public synchronized 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 synchronized 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. |
| bound | back to summary |
|---|---|
| private boolean bound Various states of this socket. | |
| bytesLeftToFilter | back to summary |
|---|---|
| private int bytesLeftToFilter | |
| closed | back to summary |
|---|---|
| private boolean closed | |
| closeLock | back to summary |
|---|---|
| private final Object closeLock | |
| connectedAddress | back to summary |
|---|---|
| pack-priv InetAddress connectedAddress | |
| connectedPort | back to summary |
|---|---|
| pack-priv int connectedPort | |
| connectState | back to summary |
|---|---|
| pack-priv int connectState | |
| created | back to summary |
|---|---|
| private volatile boolean created | |
| explicitFilter | back 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. | |
| impl | back to summary |
|---|---|
| private final DatagramSocketImpl impl | |
| infAddress | back to summary |
|---|---|
| private InetAddress infAddress The "last" interface set by setInterface on this MulticastSocket | |
| infLock | back to summary |
|---|---|
| private final Object infLock The lock on the socket's interface - used by setInterface and getInterface | |
| interfaceSet | back to summary |
|---|---|
| private boolean interfaceSet Used on some platforms to record if an outgoing interface has been set for this socket. | |
| options | back to summary |
|---|---|
| private volatile Set<SocketOption<?>> options | |
| optionsLock | back to summary |
|---|---|
| private final Object optionsLock | |
| ST_CONNECTED | back to summary |
|---|---|
| pack-priv static final int ST_CONNECTED | |
| ST_NOT_CONNECTED | back to summary |
|---|---|
| pack-priv static final int ST_NOT_CONNECTED | |
| NetMulticastSocket | back to summary |
|---|---|
| pack-priv NetMulticastSocket(DatagramSocketImpl impl) This constructor is also used by
| |
| bind | back to summary |
|---|---|
| public synchronized void bind(SocketAddress addr) throws SocketException Overrides java. Doc from java. Binds this DatagramSocket to a specific address and port.
If the address is
| |
| checkAddress | back to summary |
|---|---|
| pack-priv static void checkAddress(InetAddress addr, String op) | |
| checkFiltering | back to summary |
|---|---|
| private boolean checkFiltering(DatagramPacket p) throws SocketException | |
| 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 addr) 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 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.
| |
| 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.
| |
| getBroadcast | back to summary |
|---|---|
| public synchronized boolean getBroadcast() throws SocketException Overrides java. Doc from java. Tests if SO_BROADCAST is enabled.
| |
| getImpl | back to summary |
|---|---|
| pack-priv final DatagramSocketImpl getImpl() throws SocketException Return 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.
| |
| 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 synchronized 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 synchronized boolean getReuseAddress() throws SocketException Overrides java. Doc from java. Tests if SO_REUSEADDR is enabled.
| |
| getSendBufferSize | back to summary |
|---|---|
| public synchronized int getSendBufferSize() throws SocketException Overrides java. Doc from java. Get value of the SO_SNDBUF option for this
| |
| getSoTimeout | back to summary |
|---|---|
| public synchronized 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 synchronized 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 mcastaddr) 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 mcastaddr) 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.
| |
| receive | back to summary |
|---|---|
| public synchronized 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
| |
| setBroadcast | back to summary |
|---|---|
| public synchronized 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.
| |
| 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 synchronized 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 synchronized 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 synchronized 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 synchronized 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 synchronized 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.
| |