# Connection (sshj 0.4.1 API)
Date: 2011-06-19

## net.schmizz.sshj.connection
Interface Connection

All Known Implementing Classes:
  ConnectionImpl

    public interface Connection

Connection layer of the SSH protocol. Refer to RFC 254.

Method Summary
`void` `attach(Channel chan)` Attach a `Channel` to this connection.
`void` `attach(ForwardedChannelOpener opener)` Attach a `ForwardedChannelOpener` to this connection, which will be delegated opening of any `CHANNEL_OPEN` packets `for which it is responsible`.
`void` `forget(Channel chan)` Forget an attached `Channel`.
`void` `forget(ForwardedChannelOpener opener)` Forget an attached `ForwardedChannelOpener`.
`Channel` `get(int id)`
`ForwardedChannelOpener` `get(String chanType)`
`int` `getMaxPacketSize()`
`int` `getTimeout()`
`Transport` `getTransport()`
`int` `getWindowSize()`
`void` `join()` Wait for the situation that no channels are attached (e.g., got closed).
`int` `nextID()`
`Promise<SSHPacket,ConnectionException>` `sendGlobalRequest(String name, boolean wantReply, byte[] specifics)` Send an SSH global request.
`void` `sendOpenFailure(int recipient, OpenFailException.Reason reason, String message)` Send a `SSH_MSG_OPEN_FAILURE` for specified `Reason` and `message`.
`void` `setMaxPacketSize(int maxPacketSize)` Set the maximum packet size for the local window this connection recommends to any `Channel`'s that ask for it.
`void` `setTimeout(int timeout)` Set the `timeout` this connection uses for blocking operations and recommends to any `other` `classes` that ask for it.
`void` `setWindowSize(int windowSize)` Set the size for the local window this connection recommends to any `Channel`'s that ask for it.

Method Detail

### attach

    void attach(Channel chan)

  Attach a `Channel` to this connection. A channel must be attached to the connection if it is to receive any channel-specific data that is received.

  Parameters:
    `chan` - the channel

### attach

    void attach(ForwardedChannelOpener opener)

  Attach a `ForwardedChannelOpener` to this connection, which will be delegated opening of any `CHANNEL_OPEN` packets `for which it is responsible`.

  Parameters:
    `opener` - an opener for forwarded channels

### forget

    void forget(Channel chan)

  Forget an attached `Channel`.

  Parameters:
    `chan` - the channel

### forget

    void forget(ForwardedChannelOpener opener)

  Forget an attached `ForwardedChannelOpener`.

  Parameters:
    `opener` - the opener to forget

### get

    Channel get(int id)

  Parameters:
    `id` - number of the channel to retrieve
  Returns:
    an attached `Channel` of specified channel number, or `null` if no such channel was attached

### join

    void join()
              throws InterruptedException

  Wait for the situation that no channels are attached (e.g., got closed).

  Throws:
    `InterruptedException` - if the thread is interrupted

### get

    ForwardedChannelOpener get(String chanType)

  Parameters:
    `chanType` - channel type
  Returns:
    an attached `ForwardedChannelOpener` of specified channel-type, or `null` if no such channel was attached

### nextID

    int nextID()

  Returns:
    an available ID a `Channel` can rightfully claim.

### sendGlobalRequest

    Promise<SSHPacket,ConnectionException> sendGlobalRequest(String name,
                                                             boolean wantReply,
                                                             byte[] specifics)
                                                             throws TransportException

  Send an SSH global request.

  Parameters:
    `name` - request name
    `wantReply` - whether a reply is requested
    `specifics` - `SSHPacket` containing fields specific to the request
  Returns:
    a `Promise` for the reply data (in case `wantReply` is true) which allows waiting on the reply, or `null` if a reply is not requested.
  Throws:
    `TransportException` - if there is an error sending the request

### sendOpenFailure

    void sendOpenFailure(int recipient,
                         OpenFailException.Reason reason,
                         String message)
                         throws TransportException

  Send a `SSH_MSG_OPEN_FAILURE` for specified `Reason` and `message`.

  Parameters:
    `recipient` - number of the recipient channel
    `reason` - a reason for the failure
    `message` - an explanatory message
  Throws:
    `TransportException` - if there is a transport-layer error

### getMaxPacketSize

    int getMaxPacketSize()

  Returns:
    the maximum packet size for the local window this connection recommends to any `Channel`'s that ask for it.

### setMaxPacketSize

    void setMaxPacketSize(int maxPacketSize)

  Set the maximum packet size for the local window this connection recommends to any `Channel`'s that ask for it.

  Parameters:
    `maxPacketSize` - maximum packet size in bytes

### getWindowSize

    int getWindowSize()

  Returns:
    the size for the local window this connection recommends to any `Channel`'s that ask for it.

### setWindowSize

    void setWindowSize(int windowSize)

  Set the size for the local window this connection recommends to any `Channel`'s that ask for it.

  Parameters:
    `windowSize` - window size in bytes

### getTransport

    Transport getTransport()

  Returns:
    the associated `Transport`.

### getTimeout

    int getTimeout()

  Returns:
    the `timeout` in seconds that this connection uses for blocking operations and recommends to any `other` `classes` that ask for it.

### setTimeout

    void setTimeout(int timeout)

  Set the `timeout` this connection uses for blocking operations and recommends to any `other` `classes` that ask for it.

  Parameters:
    `timeout` - timeout in seconds

Copyright © 2009-2011. All Rights Reserved.