net.i2p.client.streaming

## Interface I2PSocket

- All Superinterfaces:
    AutoCloseable, Closeable
  All Known Implementing Classes:
    I2PSocketFull, SocketWrapper

      public interface I2PSocket
      extends Closeable

  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.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Interface and Description
    --- | ---
    `static interface` | `I2PSocket.SocketErrorListener` Deprecated, unimplemented, does nothing.

  - ### Method Summary

    All Methods Instance Methods Abstract Methods
    Modifier and Type | Method and Description
    --- | ---
    `InputStream` | `getInputStream()` As of 0.9.9 will throw an IOE if socket is closed.
    `int` | `getLocalPort()` The local port.
    `I2PSocketOptions` | `getOptions()`
    `OutputStream` | `getOutputStream()` As of 0.9.9 will throw an IOE if socket is closed.
    `Destination` | `getPeerDestination()`
    `int` | `getPort()` The remote port.
    `long` | `getReadTimeout()` How long we will wait blocked on a read() operation.
    `Destination` | `getThisDestination()`
    `boolean` | `isClosed()`
    `void` | `reset()` Resets and closes this socket.
    `void` | `setOptions(I2PSocketOptions options)` Configure the socket
    `void` | `setReadTimeout(long ms)` Define how long we will wait blocked on a read() operation (-1 will make the socket wait forever).
    `void` | `setSocketErrorListener(I2PSocket.SocketErrorListener lsnr)` Deprecated, unimplemented, does nothing

    - ### Methods inherited from interface java.io.Closeable

      `close`

- - ### Method Detail

    - #### getInputStream

          InputStream getInputStream()
                              throws IOException

      As of 0.9.9 will throw an IOE if socket is closed. Prior to that would return null instead of throwing IOE.

      Note that operations on the returned stream may return an `IOException` whose cause as returned by `Throwable.getCause()` is an `I2PSocketException`. If so, the client may retrieve a status code via `I2PSocketException.getStatus()` to provide specific feedback to the user.

      Returns:
        an InputStream to read from the socket. Non-null since 0.9.9.
      Throws:
        `IOException` - on failure

    - #### getLocalPort

          int getLocalPort()

      The local port.
      Returns:
        Default I2PSession.PORT_UNSPECIFIED (0) or PORT_ANY (0)

    - #### getOptions

          I2PSocketOptions getOptions()

      Returns:
        socket's configuration

    - #### getOutputStream

          OutputStream getOutputStream()
                                throws IOException

      As of 0.9.9 will throw an IOE if socket is closed. Prior to that would return null instead of throwing IOE.

      Note that operations on the returned stream may return an `IOException` whose cause as returned by `Throwable.getCause()` is an `I2PSocketException`. If so, the client may retrieve a status code via `I2PSocketException.getStatus()` to provide specific feedback to the user.

      Returns:
        an OutputStream to write into the socket. Non-null since 0.9.9.
      Throws:
        `IOException` - on failure

    - #### getPeerDestination

          Destination getPeerDestination()

      Returns:
        the destination of the peer.

    - #### getPort

          int getPort()

      The remote port.
      Returns:
        Default I2PSession.PORT_UNSPECIFIED (0) or PORT_ANY (0)

    - #### 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

    - #### getThisDestination

          Destination getThisDestination()

      Returns:
        the Destination of this side of the socket.

    - #### isClosed

          boolean isClosed()

    - #### reset

          void reset()
              throws IOException

      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. Nonblocking. 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`

    - #### setOptions

          void setOptions(I2PSocketOptions options)

      Configure the socket
      Parameters:
        `options` - I2PSocketOptions to set

    - #### 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

    - #### setSocketErrorListener

          void setSocketErrorListener(I2PSocket.SocketErrorListener lsnr)

      Deprecated, unimplemented, does nothing