net.i2p.sam

## Class SAMv3StreamSession

- java.lang.Object
- - net.i2p.sam.SAMStreamSession
  - - net.i2p.sam.SAMv3StreamSession

- All Implemented Interfaces:
    Closeable, AutoCloseable, SAMMessageSess, Session
  Direct Known Subclasses:
    MasterSession

      class SAMv3StreamSession
      extends SAMStreamSession
      implements Session

  SAMv3 STREAM session class.

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from class net.i2p.sam.SAMStreamSession

      `SAMStreamSession.DisconnectListener, SAMStreamSession.SAMStreamSessionServer, SAMStreamSession.SAMStreamSessionSocketReader, SAMStreamSession.SAMv1StreamSessionSocketReader, SAMStreamSession.StreamSender`

  - ### Field Summary

    - ### Fields inherited from class net.i2p.sam.SAMStreamSession

      `_isOwnSession, _log, canCreate, DEFAULT_FORCE_FLUSH, forceFlush, PROP_FORCE_FLUSH, recv, server, SOCKET_HANDLER_BUF_SIZE, socketMgr`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `SAMv3StreamSession(String login)` Create a new SAM STREAM session, according to information registered with the given nickname Caller MUST call start().
    `SAMv3StreamSession(String login, Properties props, SAMv3Handler handler, I2PSocketManager mgr, int listenPort)` Build a Stream Session on an existing I2P session registered with the given nickname Caller MUST call start().

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `accept(SAMv3Handler handler, boolean verbose)` Accept a single incoming STREAM on the socket stolen from the handler.
    `void` | `close()` Close the stream session TODO Why do we override?
    `void` | `connect(SAMv3Handler handler, String dest, Properties props)` Connect the SAM STREAM session to the specified Destination for a single connection, using the socket stolen from the handler.
    `static SessionsDB` | `getDB()`
    `String` | `getNick()`
    `protected I2PServerSocket` | `getSocketServer()`
    `boolean` | `queueSocket(I2PSocket sock)` Put a socket on the accept queue.
    `void` | `startForwardingIncoming(Properties props, boolean sendPorts)` Forward sockets from I2P to the host/port provided.
    `void` | `stopForwardingIncoming()` stop Forwarding Incoming connection coming from I2P

    - ### Methods inherited from class net.i2p.sam.SAMStreamSession

      `checkSocketHandlerId, closeConnection, connect, createSocketHandler, getDestination, getListenPort, getListenProtocol, getSocketReader, isDestroyed, newSAMStreamSessionSocketReader, newStreamSender, removeSocketHandler, sendBytes, sendBytes, sendBytes, setReceiveLimit, start`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

    - ### Methods inherited from interface net.i2p.sam.SAMMessageSess

      `getDestination, getListenPort, getListenProtocol, sendBytes, sendBytes, start`

- - ### Constructor Detail

    - #### SAMv3StreamSession

          public SAMv3StreamSession(String login)
                             throws IOException,
                                    DataFormatException,
                                    SAMException

      Create a new SAM STREAM session, according to information registered with the given nickname Caller MUST call start().
      Parameters:
        `login` - The nickname
      Throws:
        `IOException`
        `DataFormatException`
        `SAMException`
        `NullPointerException` - if login nickname is not registered

    - #### SAMv3StreamSession

          public SAMv3StreamSession(String login,
                                    Properties props,
                                    SAMv3Handler handler,
                                    I2PSocketManager mgr,
                                    int listenPort)
                             throws IOException,
                                    DataFormatException,
                                    SAMException

      Build a Stream Session on an existing I2P session registered with the given nickname Caller MUST call start().
      Parameters:
        `login` - nickname of the session
      Throws:
        `IOException`
        `DataFormatException`
        `SAMException`

  - ### Method Detail

    - #### accept

          public void accept(SAMv3Handler handler,
                             boolean verbose)
                      throws I2PException,
                             InterruptedIOException,
                             IOException,
                             SAMException

      Accept a single incoming STREAM on the socket stolen from the handler. As of version 3.2 (0.9.24), multiple simultaneous accepts are allowed. Accepts and forwarding may not be done at the same time.
      Parameters:
        `handler` - The handler that communicates with the requesting client
        `verbose` - If true, SAM will send the Base64-encoded peer Destination of an incoming socket as the first line of data sent to its client on the handler socket
      Throws:
        `DataFormatException` - if the destination is not valid
        `ConnectException` - if the destination refuses connections
        `NoRouteToHostException` - if the destination can't be reached
        `InterruptedIOException` - if the connection timeouts
        `I2PException` - if there's another I2P-related error
        `IOException`
        `SAMException`

    - #### close

          public void close()

      Close the stream session TODO Why do we override?
      Specified by:
        `close` in interface `Closeable`
      Specified by:
        `close` in interface `AutoCloseable`
      Specified by:
        `close` in interface `SAMMessageSess`
      Overrides:
        `close` in class `SAMStreamSession`

    - #### connect

          public void connect(SAMv3Handler handler,
                              String dest,
                              Properties props)
                       throws I2PException,
                              ConnectException,
                              NoRouteToHostException,
                              DataFormatException,
                              InterruptedIOException,
                              IOException

      Connect the SAM STREAM session to the specified Destination for a single connection, using the socket stolen from the handler.
      Parameters:
        `handler` - The handler that communicates with the requesting client
        `dest` - Base64-encoded Destination to connect to
        `props` - Options to be used for connection
      Throws:
        `DataFormatException` - if the destination is not valid
        `ConnectException` - if the destination refuses connections
        `NoRouteToHostException` - if the destination can't be reached
        `InterruptedIOException` - if the connection timeouts
        `I2PException` - if there's another I2P-related error
        `IOException`

    - #### getDB

          public static SessionsDB getDB()

    - #### getNick

          public String getNick()

      Specified by:
        `getNick` in interface `Session`

    - #### getSocketServer

          protected I2PServerSocket getSocketServer()

    - #### queueSocket

          public boolean queueSocket(I2PSocket sock)

      Put a socket on the accept queue. Only for subsession, throws IllegalStateException otherwise.
      Returns:
        success, false if full

    - #### startForwardingIncoming

          public void startForwardingIncoming(Properties props,
                                              boolean sendPorts)
                                       throws SAMException,
                                              InterruptedIOException

      Forward sockets from I2P to the host/port provided. Accepts and forwarding may not be done at the same time.
      Throws:
        `SAMException`
        `InterruptedIOException`

    - #### stopForwardingIncoming

          public void stopForwardingIncoming()
                                      throws SAMException,
                                             InterruptedIOException

      stop Forwarding Incoming connection coming from I2P
      Throws:
        `SAMException`
        `InterruptedIOException`