public class MultiplexingDatagramSocket extends SafeCloseDatagramSocket
Modifier and Type | Field and Description |
---|---|
private MultiplexingXXXSocketSupport<MultiplexedDatagramSocket> |
multiplexingXXXSocketSupport
The
MultiplexingXXXSocketSupport which implements functionality
common to TCP and UDP sockets in order to facilitate implementers such as
this instance. |
private boolean |
persistent
Whether this socket should be kept open even when all of its
MultiplexedDatagramSocket are closed (if the value is
true ), or it should be closed when the last of its
MultiplexedDatagramSocket is closed (if the value is
false ). |
private List<DatagramPacket> |
received
The list of DatagramPackets to be received through this
DatagramSocket i.e.
|
private int |
soTimeout
Buffer variable for storing the SO_TIMEOUT value set by the
last setSoTimeout() call.
|
delegate
Constructor and Description |
---|
MultiplexingDatagramSocket()
Initializes a new MultiplexingDatagramSocket instance which is
to enable DatagramPacket filtering and binds it to any available
port on the local host machine.
|
MultiplexingDatagramSocket(boolean persistent)
Initializes a new MultiplexingDatagramSocket instance which is
to enable DatagramPacket filtering and binds it to any available
port on the local host machine.
|
MultiplexingDatagramSocket(DatagramSocket delegate)
Initializes a new MultiplexingDatagramSocket instance which is
to enable DatagramPacket filtering on a specific
DatagramSocket.
|
MultiplexingDatagramSocket(DatagramSocket delegate,
boolean persistent)
Initializes a new MultiplexingDatagramSocket instance which is
to enable DatagramPacket filtering on a specific
DatagramSocket.
|
MultiplexingDatagramSocket(int port)
Initializes a new MultiplexingDatagramSocket instance which is
to enable DatagramPacket filtering and binds it to the specified
port on the local host machine.
|
MultiplexingDatagramSocket(int port,
boolean persistent)
Initializes a new MultiplexingDatagramSocket instance which is
to enable DatagramPacket filtering and binds it to the specified
port on the local host machine.
|
MultiplexingDatagramSocket(int port,
InetAddress laddr)
Initializes a new MultiplexingDatagramSocket instance which is
to enable DatagramPacket filtering, bound to the specified local
address.
|
MultiplexingDatagramSocket(int port,
InetAddress laddr,
boolean persistent)
Initializes a new MultiplexingDatagramSocket instance which is
to enable DatagramPacket filtering, bound to the specified local
address.
|
MultiplexingDatagramSocket(SocketAddress bindaddr)
Initializes a new MultiplexingDatagramSocket instance which is
to enable DatagramPacket filtering, bound to the specified local
socket address.
|
MultiplexingDatagramSocket(SocketAddress bindaddr,
boolean persistent)
Initializes a new MultiplexingDatagramSocket instance which is
to enable DatagramPacket filtering, bound to the specified local
socket address.
|
Modifier and Type | Method and Description |
---|---|
(package private) void |
close(MultiplexedDatagramSocket multiplexed)
Closes a specific MultiplexedDatagramSocket which filters
DatagramPackets away from this DatagramSocket.
|
MultiplexedDatagramSocket |
getSocket(DatagramPacketFilter filter)
Gets a MultiplexedDatagramSocket which filters
DatagramPackets away from this DatagramSocket using a
specific DatagramPacketFilter.
|
MultiplexedDatagramSocket |
getSocket(DatagramPacketFilter filter,
boolean create)
Gets a MultiplexedDatagramSocket which filters
DatagramPackets away from this DatagramSocket using a
specific DatagramPacketFilter.
|
int |
getSoTimeout()
Retrieves setting for SO_TIMEOUT.
|
private void |
multiplexingXXXSocketSupportDoReceive(DatagramPacket p)
Implements
MultiplexingXXXSocketSupport.doReceive(DatagramPacket)
on behalf of multiplexingXXXSocketSupport . |
private void |
multiplexingXXXSocketSupportDoSetReceiveBufferSize(int receiveBufferSize)
Implements
MultiplexingXXXSocketSupport.doSetReceiveBufferSize(int) on
behalf of multiplexingXXXSocketSupport . |
void |
receive(DatagramPacket p)
Receives a datagram packet from this socket.
|
(package private) void |
receive(MultiplexedDatagramSocket multiplexed,
DatagramPacket p)
Receives a DatagramPacket from this DatagramSocket upon
request from a specific MultiplexedDatagramSocket.
|
void |
setReceiveBufferSize(int receiveBufferSize)
Sets the SO_RCVBUF option to the specified value for this
DatagramSocket.
|
void |
setSoTimeout(int timeout)
Enables/disables SO_TIMEOUT with the specified timeout, in
milliseconds.
|
close
bind, connect, connect, disconnect, getBroadcast, getChannel, getInetAddress, getLocalAddress, getLocalPort, getLocalSocketAddress, getPort, getReceiveBufferSize, getRemoteSocketAddress, getReuseAddress, getSendBufferSize, getTrafficClass, isBound, isClosed, isConnected, logNonStun, send, setBroadcast, setDefaultDelegateFactory, setDefaultReceiveBufferSize, setReuseAddress, setSendBufferSize, setTrafficClass
setDatagramSocketImplFactory
private final MultiplexingXXXSocketSupport<MultiplexedDatagramSocket> multiplexingXXXSocketSupport
MultiplexingXXXSocketSupport
which implements functionality
common to TCP and UDP sockets in order to facilitate implementers such as
this instance.private final List<DatagramPacket> received
MultiplexedDatagramSocket
of this instance at the time of the
reading from the network.private int soTimeout
private final boolean persistent
MultiplexedDatagramSocket
are closed (if the value is
true
), or it should be closed when the last of its
MultiplexedDatagramSocket
is closed (if the value is
false
).public MultiplexingDatagramSocket() throws SocketException
SocketException
- if the socket could not be opened, or the socket
could not bind to the specified local portDatagramSocket.DatagramSocket()
public MultiplexingDatagramSocket(boolean persistent) throws SocketException
persistent
- whether this socket should be kept open after all of
its MultiplexedDatagramSocket
s are closed.SocketException
- if the socket could not be opened, or the socket
could not bind to the specified local portDatagramSocket.DatagramSocket()
public MultiplexingDatagramSocket(DatagramSocket delegate) throws SocketException
delegate
- the DatagramSocket on which
DatagramPacket filtering is to be enabled by the new instanceSocketException
- if anything goes wrong while initializing the new
instancepublic MultiplexingDatagramSocket(DatagramSocket delegate, boolean persistent) throws SocketException
delegate
- the DatagramSocket on which
DatagramPacket filtering is to be enabled by the new instancepersistent
- whether this socket should be kept open after all of
its MultiplexedDatagramSocket
s are closed.SocketException
- if anything goes wrong while initializing the new
instancepublic MultiplexingDatagramSocket(int port) throws SocketException
port
- the port to bind the new socket toSocketException
- if the socket could not be opened, or the socket
could not bind to the specified local portDatagramSocket.DatagramSocket(int)
public MultiplexingDatagramSocket(int port, boolean persistent) throws SocketException
port
- the port to bind the new socket topersistent
- whether this socket should be kept open after all of
its MultiplexedDatagramSocket
s are closed.SocketException
- if the socket could not be opened, or the socket
could not bind to the specified local portDatagramSocket.DatagramSocket(int)
public MultiplexingDatagramSocket(int port, InetAddress laddr) throws SocketException
port
- the local port to bind the new socket toladdr
- the local address to bind the new socket toSocketException
- if the socket could not be opened, or the socket
could not bind to the specified local portDatagramSocket.DatagramSocket(int, InetAddress)
public MultiplexingDatagramSocket(int port, InetAddress laddr, boolean persistent) throws SocketException
port
- the local port to bind the new socket toladdr
- the local address to bind the new socket topersistent
- whether this socket should be kept open after all of
its MultiplexedDatagramSocket
s are closed.SocketException
- if the socket could not be opened, or the socket
could not bind to the specified local portDatagramSocket.DatagramSocket(int, InetAddress)
public MultiplexingDatagramSocket(SocketAddress bindaddr) throws SocketException
If the specified local socket address is null, creates an unbound socket.
bindaddr
- local socket address to bind, or null for an
unbound socketSocketException
- if the socket could not be opened, or the socket
could not bind to the specified local portDatagramSocket.DatagramSocket(SocketAddress)
public MultiplexingDatagramSocket(SocketAddress bindaddr, boolean persistent) throws SocketException
If the specified local socket address is null, creates an unbound socket.
bindaddr
- local socket address to bind, or null for an
unbound socketpersistent
- whether this socket should be kept open after all of
its MultiplexedDatagramSocket
s are closed.SocketException
- if the socket could not be opened, or the socket
could not bind to the specified local portDatagramSocket.DatagramSocket(SocketAddress)
void close(MultiplexedDatagramSocket multiplexed)
multiplexed
- the MultiplexedDatagramSocket to closepublic MultiplexedDatagramSocket getSocket(DatagramPacketFilter filter) throws SocketException
filter
- the DatagramPacketFilter to get a
MultiplexedDatagramSocket forSocketException
- if creating the
MultiplexedDatagramSocket for the specified filter
failspublic MultiplexedDatagramSocket getSocket(DatagramPacketFilter filter, boolean create) throws SocketException
filter
- the DatagramPacketFilter to get a
MultiplexedDatagramSocket forcreate
- whether or not to create a
MultiplexedDatagramSocket if this instance does not already have
a socket for the given filter.SocketException
- if creating the
MultiplexedDatagramSocket for the specified filter
fails.public int getSoTimeout()
getSoTimeout
in class DelegatingDatagramSocket
DatagramSocket.getSoTimeout()
private void multiplexingXXXSocketSupportDoReceive(DatagramPacket p) throws IOException
MultiplexingXXXSocketSupport.doReceive(DatagramPacket)
on behalf of multiplexingXXXSocketSupport
. Receives a
DatagramPacket
from this socket.p
- the DatagramPacket
into which to place the incoming dataIOException
- if an I/O error occursprivate void multiplexingXXXSocketSupportDoSetReceiveBufferSize(int receiveBufferSize) throws SocketException
MultiplexingXXXSocketSupport.doSetReceiveBufferSize(int)
on
behalf of multiplexingXXXSocketSupport
. 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.receiveBufferSize
- the size to which to set the receive buffer sizeSocketException
- if there is an error in the underlying protocol,
such as a UDP errorpublic void receive(DatagramPacket p) throws IOException
This method blocks until a datagram is received. 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.
receive
in class SafeCloseDatagramSocket
p
- the DatagramPacket into which to place the incoming
dataIOException
- if an I/O error occursSocketTimeoutException
- if setSoTimeout(int) was
previously called and the timeout has expiredDatagramSocket.receive(DatagramPacket)
void receive(MultiplexedDatagramSocket multiplexed, DatagramPacket p) throws IOException
multiplexed
- the MultiplexedDatagramSocket which requests
the receipt of a DatagramPacket from the networkp
- the DatagramPacket to receive the data from the networkIOException
- if an I/O error occursSocketTimeoutException
- if setSoTimeout(int) was
previously called on multiplexed and the timeout has expiredpublic void setReceiveBufferSize(int receiveBufferSize) throws SocketException
Because SO_RCVBUF is a hint, applications that want to verify
what size the buffers were set to should call
DelegatingDatagramSocket.getReceiveBufferSize()
.
setReceiveBufferSize
in class DelegatingDatagramSocket
receiveBufferSize
- the size to which to set the receive buffer size. The value
must be greater than zeroSocketException
- if there is an error in the underlying protocol,
such as an UDP errorDatagramSocket.setReceiveBufferSize(int)
public void setSoTimeout(int timeout) throws SocketException
DelegatingDatagramSocket.receive(DatagramPacket)
for this DatagramSocket will
block for only this amount of time. If the timeout expires, a
SocketTimeoutException is raised, though the
DatagramSocket is still valid. The option must be enabled prior
to entering the blocking operation to have effect. The timeout must be
greater than zero. A timeout of zero is interpreted as an infinite
timeout.setSoTimeout
in class DelegatingDatagramSocket
timeout
- the specified timeout in millisecondsSocketException
- if there is an error in the underlying protocol,
such as an UDP errorDatagramSocket.setSoTimeout(int)
Copyright © 2018. All rights reserved.