public class MultiplexedSocket extends DelegatingSocket implements MultiplexedXXXSocket
Modifier and Type | Class and Description |
---|---|
private class |
MultiplexedSocket.InputStreamImpl
Implements an InputStream for this MultiplexedSocket,
reading data using
receive(java.net.DatagramPacket) . |
Modifier and Type | Field and Description |
---|---|
private DatagramPacketFilter |
filter
The DatagramPacketFilter which determines which
DatagramPackets read from the network by
multiplexing
are to be received through this instance. |
private InputStream |
inputStream
The custom InputStream for this MultiplexedSocket.
|
private static Logger |
logger
The Logger used by the MultiplexedSocket class and its
instances for logging output.
|
private MultiplexingSocket |
multiplexing
The MultiplexingSocket which does the actual reading from the
network and which forwards DatagramPackets accepted by
filter for receipt to this instance. |
(package private) List<DatagramPacket> |
received
The list of DatagramPackets to be received through this
Socket i.e.
|
channel, delegate
Constructor and Description |
---|
MultiplexedSocket(MultiplexingSocket multiplexing,
DatagramPacketFilter filter)
Initializes a new MultiplexedSocket which is unbound and filters
DatagramPackets away from a specific MultiplexingSocket
using a specific DatagramPacketFilter.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes this datagram socket.
|
DatagramPacketFilter |
getFilter()
Gets the
DatagramPacketFilter which determines which
DatagramPacket s read from the network are to be received through
this socket. |
InputStream |
getInputStream() |
void |
receive(DatagramPacket p)
Receives a datagram packet from this socket.
|
bind, connect, connect, getChannel, getInetAddress, getKeepAlive, getLocalAddress, getLocalPort, getLocalSocketAddress, getOOBInline, getOutputStream, getPort, getReceiveBufferSize, getRemoteSocketAddress, getReuseAddress, getSendBufferSize, getSoLinger, getSoTimeout, getTcpNoDelay, getTrafficClass, isBound, isClosed, isConnected, isInputShutdown, isOutputShutdown, receiveFromInputStream, send, sendUrgentData, setKeepAlive, setOOBInline, setOriginalInputStream, setPerformancePreferences, setReceiveBufferSize, setReuseAddress, setSendBufferSize, setSoLinger, setSoTimeout, setTcpNoDelay, setTrafficClass, shutdownInput, shutdownOutput, toString
setSocketImplFactory
private static final Logger logger
private final DatagramPacketFilter filter
multiplexing
are to be received through this instance.private final InputStream inputStream
private final MultiplexingSocket multiplexing
filter
for receipt to this instance.final List<DatagramPacket> received
filter
.MultiplexedSocket(MultiplexingSocket multiplexing, DatagramPacketFilter filter) throws SocketException
multiplexing
- the MultiplexingSocket which does the actual
reading from the network and which forwards DatagramPackets
accepted by the specified filter to the new instancefilter
- the DatagramPacketFilter which determines which
DatagramPackets read from the network by the specified
multiplexing are to be received through the new instanceSocketException
- if the socket could not be openedpublic void close()
Any thread currently blocked in receive(DatagramPacket)
upon
this socket will throw a SocketException
.
close
in interface Closeable
close
in interface AutoCloseable
close
in class DelegatingSocket
Socket.close()
public DatagramPacketFilter getFilter()
DatagramPacketFilter
which determines which
DatagramPacket
s read from the network are to be received through
this socket.getFilter
in interface MultiplexedXXXSocket
DatagramPacketFilter
which determines which
DatagramPacket
s read from the network are to be received through
this socketpublic InputStream getInputStream()
getInputStream
in class DelegatingSocket
public 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 DelegatingSocket
p
- the DatagramPacket into which to place the incoming
dataIOException
- if an I/O error occursMultiplexingSocket.receive(DatagramPacket)
Copyright © 2018. All rights reserved.