- All Superinterfaces:
AutoCloseable, Closeable
- All Known Implementing Classes:
I2PSocketFull, SocketWrapper
Streaming socket returned by
I2PSocketManager.connect(Destination). Note that this is not a standard Java Socket, if you need one of those, use I2PSocketManager.connectToSocket(Destination) instead.
Method Summary
Modifier and TypeMethodDescriptionThrows an IOException if the socket is closed; never returns null.default longHow many bytes have been received over the lifetime of this socket.default longHow many bytes have been sent over the lifetime of this socket.intThe local port.The options governing this socket's behaviour.Throws an IOException if the socket is closed; never returns null.The destination of the connected peer.intgetPort()The remote port.longHow long we will wait blocked on a read() operation.Returns the Destination of this side of the socket.booleanisClosed()Whether this socket has been closed.voidreset()Resets and closes this socket.voidsetOptions(I2PSocketOptions options) Configure the socket.voidsetReadTimeout(long ms) Define how long we will wait blocked on a read() operation (-1 will make the socket wait forever).
Method Details
getThisDestination
Destination getThisDestination()Returns the Destination of this side of the socket.- Returns:
- the Destination of this side of the socket
getPeerDestination
Destination getPeerDestination()The destination of the connected peer.- Returns:
- the destination of the peer
getInputStream
Throws an IOException if the socket is closed; never returns null.Note that operations on the returned stream may return an
IOExceptionwhose cause as returned byThrowable.getCause()is anI2PSocketException. If so, the client may retrieve a status code viaI2PSocketException.getStatus()to provide specific feedback to the user.- Returns:
- an InputStream to read from the socket, never null
- Throws:
IOException- on failure, including if the socket is closed
getOutputStream
Throws an IOException if the socket is closed; never returns null.Note that operations on the returned stream may return an
IOExceptionwhose cause as returned byThrowable.getCause()is anI2PSocketException. If so, the client may retrieve a status code viaI2PSocketException.getStatus()to provide specific feedback to the user.- Returns:
- an OutputStream to write into the socket, never null
- Throws:
IOException- on failure, including if the socket is closed
getOptions
I2PSocketOptions getOptions()The options governing this socket's behaviour.- Returns:
- the I2PSocketOptions governing this socket
setOptions
Configure the socket.- Parameters:
options- I2PSocketOptions to set
getReadTimeout
long getReadTimeout()How long we will wait blocked on a read() operation. This is simply a helper to query the I2PSocketOptions.- Returns:
- milliseconds to wait, or -1 if we will wait indefinitely
setReadTimeout
void setReadTimeout(long ms) Define how long we will wait blocked on a read() operation (-1 will make the socket wait forever). This is simply a helper to adjust the I2PSocketOptions.- Parameters:
ms- timeout in ms
isClosed
boolean isClosed()Whether this socket has been closed.- Returns:
- true if this socket has been closed
getPort
int getPort()The remote port.- Returns:
- Default I2PSession.PORT_UNSPECIFIED (0) or PORT_ANY (0)
getLocalPort
int getLocalPort()The local port.- Returns:
- Default I2PSession.PORT_UNSPECIFIED (0) or PORT_ANY (0)
getLifetimeBytesSent
default long getLifetimeBytesSent()How many bytes have been sent over the lifetime of this socket.- Returns:
- bytes sent, or 0 if unknown
getLifetimeBytesReceived
default long getLifetimeBytesReceived()How many bytes have been received over the lifetime of this socket.- Returns:
- bytes received, or 0 if unknown
reset
Resets and closes this socket. Sends a RESET indication to the far-end. This is the equivalent of setSoLinger(true, 0) followed by close() on a Java Socket. Non-blocking. Any thread currently blocked in an I/O operation upon this socket will throw an IOException. Once a socket has been reset, it is not available for further networking use (i.e. can't be reconnected or rebound). A new socket needs to be created. Resetting this socket will also close the socket's InputStream and OutputStream.- Throws:
IOException- on reset failure