public class DelegatingSocket extends Socket
Modifier and Type | Field and Description |
---|---|
protected SocketChannel |
channel
The SocketChannel (to be) returned by
getChannel() . |
protected Socket |
delegate
Delegate Socket.
|
private DelegatingSocket |
delegateAsDelegatingSocket
A DelegatingSocket view of
delegate if the latter
implements the former; otherwise, null. |
private ByteBuffer |
frameLengthByteBuffer
The ByteBuffer instance used in
receiveFromChannel(java.nio.channels.SocketChannel,
java.net.DatagramPacket) to read the 2-byte length field into. |
private InputStream |
inputStream
InputStream for this socket.
|
private long |
nbReceivedPackets
The number of non-STUN packets received for this socket.
|
private long |
nbSentPackets
The number of non-STUN packets sent for this socket.
|
private OutputStream |
outputStream
OutputStream for this socket.
|
Modifier | Constructor and Description |
---|---|
|
DelegatingSocket()
Initializes a new DelegatingSocket.
|
|
DelegatingSocket(InetAddress address,
int port)
Initializes a new DelegatingSocket.
|
|
DelegatingSocket(InetAddress address,
int port,
InetAddress localAddr,
int localPort)
Initializes a new DelegatingSocket.
|
|
DelegatingSocket(Proxy proxy)
Initializes a new DelegatingSocket.
|
|
DelegatingSocket(Socket delegate)
Initializes a new DelegatingSocket instance which is to delegate
(i.e.
|
protected |
DelegatingSocket(SocketImpl impl)
Initializes a new DelegatingSocket.
|
|
DelegatingSocket(Socket delegate,
SocketChannel channel)
Initializes a new DelegatingSocket instance which is to delegate
(i.e.
|
|
DelegatingSocket(String host,
int port)
Initializes a new DelegatingSocket.
|
|
DelegatingSocket(String host,
int port,
InetAddress localAddr,
int localPort)
Initializes a new DelegatingSocket.
|
Modifier and Type | Method and Description |
---|---|
void |
bind(SocketAddress bindpoint) |
void |
close() |
void |
connect(SocketAddress endpoint) |
void |
connect(SocketAddress endpoint,
int timeout) |
SocketChannel |
getChannel() |
InetAddress |
getInetAddress() |
InputStream |
getInputStream() |
boolean |
getKeepAlive() |
InetAddress |
getLocalAddress() |
int |
getLocalPort() |
SocketAddress |
getLocalSocketAddress() |
boolean |
getOOBInline() |
OutputStream |
getOutputStream() |
int |
getPort() |
int |
getReceiveBufferSize() |
SocketAddress |
getRemoteSocketAddress() |
boolean |
getReuseAddress() |
int |
getSendBufferSize() |
int |
getSoLinger() |
int |
getSoTimeout() |
boolean |
getTcpNoDelay() |
int |
getTrafficClass() |
boolean |
isBound() |
boolean |
isClosed() |
boolean |
isConnected() |
boolean |
isInputShutdown() |
boolean |
isOutputShutdown() |
void |
receive(DatagramPacket p)
Receives a datagram packet from this socket.
|
private void |
receiveFromChannel(SocketChannel channel,
DatagramPacket p)
Receives an RFC4571-formatted frame from channel into
p, and sets p's port and address to the remote port
and address of this Socket.
|
static void |
receiveFromInputStream(DatagramPacket p,
InputStream inputStream,
InetAddress inetAddress,
int port)
Receives an RFC4571-formatted frame from inputStream into
p, and sets p's port and address to port and
inetAddress.
|
void |
send(DatagramPacket p)
Send a datagram packet from this socket.
|
void |
sendUrgentData(int data) |
void |
setKeepAlive(boolean on) |
void |
setOOBInline(boolean on) |
void |
setOriginalInputStream(InputStream inputStream)
Set original InputStream.
|
void |
setPerformancePreferences(int connectionTime,
int latency,
int bandwidth) |
void |
setReceiveBufferSize(int size) |
void |
setReuseAddress(boolean on) |
void |
setSendBufferSize(int size) |
void |
setSoLinger(boolean on,
int linger) |
void |
setSoTimeout(int timeout) |
void |
setTcpNoDelay(boolean on) |
void |
setTrafficClass(int tc) |
void |
shutdownInput() |
void |
shutdownOutput() |
String |
toString() |
setSocketImplFactory
protected final SocketChannel channel
getChannel()
. If
null, getChannel() forwards to delegate
. (If
delegate is null, getChannel() invokes the
super implementation.protected final Socket delegate
private final DelegatingSocket delegateAsDelegatingSocket
delegate
if the latter
implements the former; otherwise, null.private final ByteBuffer frameLengthByteBuffer
receiveFromChannel(java.nio.channels.SocketChannel,
java.net.DatagramPacket)
to read the 2-byte length field into.private InputStream inputStream
private long nbReceivedPackets
private long nbSentPackets
private OutputStream outputStream
public DelegatingSocket()
public DelegatingSocket(InetAddress address, int port) throws IOException
address
- ignoredport
- ignoredIOException
- never thrownSocket.Socket(InetAddress, int)
public DelegatingSocket(InetAddress address, int port, InetAddress localAddr, int localPort) throws IOException
address
- ignoredport
- ignoredlocalAddr
- ignoredlocalPort
- ignoredIOException
- never thrownSocket.Socket(InetAddress, int, InetAddress, int)
public DelegatingSocket(Proxy proxy)
proxy
- ignoredSocket.Socket(Proxy)
public DelegatingSocket(Socket delegate)
delegate
- the Socket the new instance is to delegate topublic DelegatingSocket(Socket delegate, SocketChannel channel)
delegate
- the Socket the new instance is to delegate tochannel
- the SocketChannel to be returned by
getChannel()
. If null, getChannel() forwards
to delegate.protected DelegatingSocket(SocketImpl impl) throws SocketException
impl
- ignoredSocketException
- never thrownSocket.Socket(SocketImpl)
public DelegatingSocket(String host, int port) throws UnknownHostException, IOException
host
- ignoredport
- ignoredUnknownHostException
- never thrownIOException
- never thrownSocket.Socket(String, int)
public DelegatingSocket(String host, int port, InetAddress localAddr, int localPort)
host
- ignoredport
- ignoredlocalAddr
- ignoredlocalPort
- ignoredSocket.Socket(String, int, InetAddress, int)
public static void receiveFromInputStream(DatagramPacket p, InputStream inputStream, InetAddress inetAddress, int port) throws IOException
p
- the DatagramPacket into which to place the incoming
data.inputStream
- The TCP stream to be read.inetAddress
- The receiver address (local address) to set to the
datagram packet.port
- The receiver port (local port) to set to the datagram packet.IOException
- if an I/O error occursreceive(DatagramPacket)
public void bind(SocketAddress bindpoint) throws IOException
bind
in class Socket
IOException
public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
close
in class Socket
IOException
public void connect(SocketAddress endpoint) throws IOException
connect
in class Socket
IOException
public void connect(SocketAddress endpoint, int timeout) throws IOException
connect
in class Socket
IOException
public SocketChannel getChannel()
getChannel
in class Socket
public InetAddress getInetAddress()
getInetAddress
in class Socket
public InputStream getInputStream() throws IOException
getInputStream
in class Socket
IOException
public boolean getKeepAlive() throws SocketException
getKeepAlive
in class Socket
SocketException
public InetAddress getLocalAddress()
getLocalAddress
in class Socket
public int getLocalPort()
getLocalPort
in class Socket
public SocketAddress getLocalSocketAddress()
getLocalSocketAddress
in class Socket
public boolean getOOBInline() throws SocketException
getOOBInline
in class Socket
SocketException
public OutputStream getOutputStream() throws IOException
getOutputStream
in class Socket
IOException
public int getReceiveBufferSize() throws SocketException
getReceiveBufferSize
in class Socket
SocketException
public SocketAddress getRemoteSocketAddress()
getRemoteSocketAddress
in class Socket
public boolean getReuseAddress() throws SocketException
getReuseAddress
in class Socket
SocketException
public int getSendBufferSize() throws SocketException
getSendBufferSize
in class Socket
SocketException
public int getSoLinger() throws SocketException
getSoLinger
in class Socket
SocketException
public int getSoTimeout() throws SocketException
getSoTimeout
in class Socket
SocketException
public boolean getTcpNoDelay() throws SocketException
getTcpNoDelay
in class Socket
SocketException
public int getTrafficClass() throws SocketException
getTrafficClass
in class Socket
SocketException
public boolean isConnected()
isConnected
in class Socket
public boolean isInputShutdown()
isInputShutdown
in class Socket
public boolean isOutputShutdown()
isOutputShutdown
in class Socket
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.
p
- the DatagramPacket into which to place the incoming
dataIOException
- if an I/O error occursreceive(DatagramPacket)
private void receiveFromChannel(SocketChannel channel, DatagramPacket p) throws IOException
channel
- p
- IOException
public void send(DatagramPacket p) throws IOException
p
- DatagramPacket to sentIOException
- if something goes wrong during sendpublic void sendUrgentData(int data) throws IOException
sendUrgentData
in class Socket
IOException
public void setKeepAlive(boolean on) throws SocketException
setKeepAlive
in class Socket
SocketException
public void setOOBInline(boolean on) throws SocketException
setOOBInline
in class Socket
SocketException
public void setOriginalInputStream(InputStream inputStream)
inputStream
- InputStreampublic void setPerformancePreferences(int connectionTime, int latency, int bandwidth)
setPerformancePreferences
in class Socket
public void setReceiveBufferSize(int size) throws SocketException
setReceiveBufferSize
in class Socket
SocketException
public void setReuseAddress(boolean on) throws SocketException
setReuseAddress
in class Socket
SocketException
public void setSendBufferSize(int size) throws SocketException
setSendBufferSize
in class Socket
SocketException
public void setSoLinger(boolean on, int linger) throws SocketException
setSoLinger
in class Socket
SocketException
public void setSoTimeout(int timeout) throws SocketException
setSoTimeout
in class Socket
SocketException
public void setTcpNoDelay(boolean on) throws SocketException
setTcpNoDelay
in class Socket
SocketException
public void setTrafficClass(int tc) throws SocketException
setTrafficClass
in class Socket
SocketException
public void shutdownInput() throws IOException
shutdownInput
in class Socket
IOException
public void shutdownOutput() throws IOException
shutdownOutput
in class Socket
IOException
Copyright © 2018. All rights reserved.