java.lang.Object
java.net.Socket
net.i2p.client.streaming.impl.StandardSocket
- All Implemented Interfaces:
Closeable, AutoCloseable
Bridge to I2PSocket.
This extends Socket to make porting apps easier. Methods throw IOExceptions like Sockets do, rather than returning null for some methods.
StandardSockets are always bound, and always start out connected (unless connectDelay is > 0). You may not create an unbound StandardSocket. Create this through the SocketManager.
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanTrue once the socket is closed.private booleanFalse once the connection is lost.private booleanTrue once reading has stopped.private booleanTrue once writing has stopped.private final I2PSocketThe streaming socket being wrapped.Constructor Summary
ConstructorsMethod Summary
All MethodsModifier and TypeMethodDescriptionvoidbind(SocketAddress bindpoint) Binding is not supported.voidclose()Closes the socket and the underlying I2PSocket.voidconnect(SocketAddress endpoint) Connecting is not supported.voidconnect(SocketAddress endpoint, int timeout) Connecting is not supported.Channel is not supported.No remote address.Input stream from the underlying I2PSocket.booleanKeep-alive setting.No local address.intLocal port.Local socket address.booleanOOB inline is not supported.Output stream from the underlying I2PSocket.Returns the peer destination of the underlying I2PSocket.intgetPort()Remote port.intInbound buffer size.Remote socket address.booleanReuse address is not supported.intBuffer size.intSO_LINGER is not implemented.intSocket timeout.booleanTCP_NODELAY is not supported.intTraffic class is not supported.booleanisBound()Always bound.booleanisClosed()Whether closed.booleanWhether connected.booleanWhether the input side has been shut down.booleanWhether the output side has been shut down.voidsendUrgentData(int data) Urgent data is not supported.voidsetKeepAlive(boolean on) Keep-alive setting.voidsetOOBInline(boolean on) OOB inline setting.voidsetPerformancePreferences(int connectionTime, int latency, int bandwidth) Ignored, streaming sockets manage their own tuning.voidsetReceiveBufferSize(int size) Ignored, streaming sockets manage their own tuning.voidsetReuseAddress(boolean on) Ignored, streaming sockets manage their own tuning.voidsetSendBufferSize(int size) Ignored, streaming sockets manage their own tuning.voidsetSoLinger(boolean on, int linger) Ignored, streaming sockets manage their own tuning.voidsetSoTimeout(int timeout) Socket timeout.voidsetTcpNoDelay(boolean on) Ignored, streaming sockets manage their own tuning.voidsetTrafficClass(int tc) Ignored, streaming sockets manage their own tuning.voidShuts down the input side, closing the underlying I2PSocket.voidShuts down the output side, closing the underlying I2PSocket.toString()String representation of the underlying I2PSocket.Methods inherited from class Socket
getOption, setOption, supportedOptions
Field Details
_socket
The streaming socket being wrapped._connected
private volatile boolean _connectedFalse once the connection is lost._inputShutdown
private volatile boolean _inputShutdownTrue once reading has stopped._outputShutdown
private volatile boolean _outputShutdownTrue once writing has stopped._closed
private volatile boolean _closedTrue once the socket is closed.
Constructor Details
StandardSocket
StandardSocket(I2PSocket socket) Wraps an I2PSocket in a java.net.Socket.- Parameters:
socket- the I2PSocket that all traffic is delegated to
Method Details
bind
Binding is not supported.- Overrides:
bindin classSocket- Throws:
UnsupportedOperationException- always; the I2PSocket is supplied at construction, so there is nothing to bind
close
Closes the socket and the underlying I2PSocket.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classSocket- Throws:
IOException
connect
Connecting is not supported.- Overrides:
connectin classSocket- Throws:
UnsupportedOperationException- always; the I2PSocket is supplied at construction, so there is nothing to connect
connect
Connecting is not supported.- Overrides:
connectin classSocket- Throws:
UnsupportedOperationException- always; the I2PSocket is supplied at construction, so there is nothing to connect
getChannel
Channel is not supported.- Overrides:
getChannelin classSocket- Returns:
- null always, unimplemented
getInetAddress
No remote address.- Overrides:
getInetAddressin classSocket- Returns:
- null always
getInputStream
Input stream from the underlying I2PSocket.- Overrides:
getInputStreamin classSocket- Returns:
- the input stream
- Throws:
IOException- if the socket has no input stream
getKeepAlive
public boolean getKeepAlive()Keep-alive setting.- Overrides:
getKeepAlivein classSocket- Returns:
- true if keep-alive is enabled (inactivity action is SEND)
getLocalAddress
No local address.- Overrides:
getLocalAddressin classSocket- Returns:
- null always
getLocalPort
public int getLocalPort()Local port.- Overrides:
getLocalPortin classSocket- Returns:
- the port or 0 if unknown
getLocalSocketAddress
Local socket address.- Overrides:
getLocalSocketAddressin classSocket- Returns:
- an I2PSocketAddress, never null
getOOBInline
public boolean getOOBInline()OOB inline is not supported.- Overrides:
getOOBInlinein classSocket- Returns:
- false always
getOutputStream
Output stream from the underlying I2PSocket.- Overrides:
getOutputStreamin classSocket- Returns:
- the output stream
- Throws:
IOException- if the socket has no output stream
getPort
getReceiveBufferSize
public int getReceiveBufferSize()Inbound buffer size.- Overrides:
getReceiveBufferSizein classSocket- Returns:
- the inbound buffer size, or 64KB if options are unavailable
getRemoteSocketAddress
Remote socket address.- Overrides:
getRemoteSocketAddressin classSocket- Returns:
- an I2PSocketAddress, never null
getPeerDestination
Returns the peer destination of the underlying I2PSocket.- Returns:
- the peer destination, non-null
getReuseAddress
public boolean getReuseAddress()Reuse address is not supported.- Overrides:
getReuseAddressin classSocket- Returns:
- false always
getSendBufferSize
public int getSendBufferSize()Buffer size.- Overrides:
getSendBufferSizein classSocket- Returns:
- the buffer size, or 64KB if options are unavailable
getSoLinger
public int getSoLinger()SO_LINGER is not implemented.- Overrides:
getSoLingerin classSocket- Returns:
- -1 always (not implemented)
getSoTimeout
public int getSoTimeout()Socket timeout.- Overrides:
getSoTimeoutin classSocket- Returns:
- the socket timeout in milliseconds
getTcpNoDelay
public boolean getTcpNoDelay()TCP_NODELAY is not supported.- Overrides:
getTcpNoDelayin classSocket- Returns:
- false always
getTrafficClass
public int getTrafficClass()Traffic class is not supported.- Overrides:
getTrafficClassin classSocket- Returns:
- 0 always
isBound
isClosed
isConnected
public boolean isConnected()Whether connected.- Overrides:
isConnectedin classSocket- Returns:
- true until close() has run, since the I2PSocket arrives connected
isInputShutdown
public boolean isInputShutdown()Whether the input side has been shut down.- Overrides:
isInputShutdownin classSocket- Returns:
- true if shutdownInput has been called
isOutputShutdown
public boolean isOutputShutdown()Whether the output side has been shut down.- Overrides:
isOutputShutdownin classSocket- Returns:
- true if shutdownOutput has been called
sendUrgentData
public void sendUrgentData(int data) Urgent data is not supported.- Overrides:
sendUrgentDatain classSocket- Throws:
UnsupportedOperationException- always; the underlying I2PSocket has no urgent-data channel
setKeepAlive
public void setKeepAlive(boolean on) Keep-alive setting.- Overrides:
setKeepAlivein classSocket- Parameters:
on- true to enable keep-alive (inactivity action SEND), false for NOOP
setOOBInline
public void setOOBInline(boolean on) OOB inline setting.- Overrides:
setOOBInlinein classSocket- Parameters:
on- true to throw UnsupportedOperationException, false does nothing- Throws:
UnsupportedOperationException- if on is true
setPerformancePreferences
public void setPerformancePreferences(int connectionTime, int latency, int bandwidth) Ignored, streaming sockets manage their own tuning.setReceiveBufferSize
public void setReceiveBufferSize(int size) Ignored, streaming sockets manage their own tuning.- Overrides:
setReceiveBufferSizein classSocket
setReuseAddress
public void setReuseAddress(boolean on) Ignored, streaming sockets manage their own tuning.- Overrides:
setReuseAddressin classSocket
setSendBufferSize
public void setSendBufferSize(int size) Ignored, streaming sockets manage their own tuning.- Overrides:
setSendBufferSizein classSocket
setSoLinger
public void setSoLinger(boolean on, int linger) Ignored, streaming sockets manage their own tuning.- Overrides:
setSoLingerin classSocket
setSoTimeout
Socket timeout.- Overrides:
setSoTimeoutin classSocket- Parameters:
timeout- the timeout in milliseconds- Throws:
SocketException- if the options are unavailable
setTcpNoDelay
public void setTcpNoDelay(boolean on) Ignored, streaming sockets manage their own tuning.- Overrides:
setTcpNoDelayin classSocket
setTrafficClass
public void setTrafficClass(int tc) Ignored, streaming sockets manage their own tuning.- Overrides:
setTrafficClassin classSocket
shutdownInput
Shuts down the input side, closing the underlying I2PSocket.- Overrides:
shutdownInputin classSocket- Throws:
IOException
shutdownOutput
Shuts down the output side, closing the underlying I2PSocket.- Overrides:
shutdownOutputin classSocket- Throws:
IOException
toString