# Transport (sshj 0.4.0 API)
Date: 2011-06-06

## net.schmizz.sshj.transport
Interface Transport

All Superinterfaces:
  SSHPacketHandler

All Known Implementing Classes:
  TransportImpl

    public interface Transport

extends SSHPacketHandler

Transport layer of the SSH protocol.

Method Summary
`void` `addHostKeyVerifier(HostKeyVerifier hkv)` Adds the specified verifier.
`void` `disconnect()` Send a disconnection packet with reason as `DisconnectReason.BY_APPLICATION`, and closes this transport.
`void` `disconnect(DisconnectReason reason)` Send a disconnect packet with the given `reason`, and closes this transport.
`void` `disconnect(DisconnectReason reason, String message)` Send a disconnect packet with the given `reason` and `message`, and closes this transport.
`void` `doKex()` Do key exchange and algorithm negotiation.
`String` `getClientVersion()`
`Config` `getConfig()`
`DisconnectListener` `getDisconnectListener()`
`int` `getHeartbeatInterval()`
`String` `getRemoteHost()`
`int` `getRemotePort()`
`String` `getServerVersion()` Returns the version string as sent by the SSH server for identification purposes, e.g.
`Service` `getService()`
`byte[]` `getSessionID()`
`int` `getTimeout()`
`void` `init(String host, int port, InputStream in, OutputStream out)` Sets the host information and the streams to be used by this transport.
`boolean` `isAuthenticated()`
`boolean` `isRunning()`
`void` `join()` Joins the thread calling this method to the transport's death.
`void` `join(int timeout, TimeUnit unit)` Joins the thread calling this method to the transport's death.
`void` `reqService(Service service)` Request a SSH service represented by a `Service` instance.
`long` `sendUnimplemented()` Sends SSH_MSG_UNIMPLEMENTED in response to the last packet received.
`void` `setAuthenticated()` Informs this transport that authentication has been completed.
`void` `setDisconnectListener(DisconnectListener listener)` Specify a `listener` that will be notified upon disconnection.
`void` `setHeartbeatInterval(int interval)`
`void` `setService(Service service)` Sets the currently active `Service`.
`void` `setTimeout(int timeout)` Set a timeout for methods that may block.
`long` `write(SSHPacket payload)` Write a packet over this transport.

Methods inherited from interface net.schmizz.sshj.common.SSHPacketHandler
`handle`

Method Detail

### init

    void init(String host,
              int port,
              InputStream in,
              OutputStream out)
              throws TransportException

  Sets the host information and the streams to be used by this transport. Identification information is exchanged with the server. A `TransportException` is thrown in case of SSH protocol version incompatibility.

  Parameters:
    `host` - server's hostname
    `port` - server's port
    `in` - input stream for the connection
    `out` - output stream for the connection
  Throws:
    `TransportException` - if there is an error during exchange of identification information

### addHostKeyVerifier

    void addHostKeyVerifier(HostKeyVerifier hkv)

  Adds the specified verifier.

  Parameters:
    `hkv` - the host key verifier

### doKex

    void doKex()
               throws TransportException

  Do key exchange and algorithm negotiation. This can be the initial one or for algorithm renegotiation.

  Throws:
    `TransportException` - if there was an error during key exchange

### getClientVersion

    String getClientVersion()

  Returns:
    the version string used by this client to identify itself to an SSH server, e.g. "SSHJ_3_0"

### getConfig

    Config getConfig()

  Returns:
    the `Config` associated with this transport.

### getTimeout

    int getTimeout()

  Returns:
    the timeout that is currently set for blocking operations.

### setTimeout

    void setTimeout(int timeout)

  Set a timeout for methods that may block.

  Parameters:
    `timeout` - the timeout in seconds

### getHeartbeatInterval

    int getHeartbeatInterval()

  Returns:
    the interval in seconds at which a heartbeat message is sent to the server

### setHeartbeatInterval

    void setHeartbeatInterval(int interval)

  Parameters:
    `interval` - the interval in seconds, `0` means no hearbeat

### getRemoteHost

    String getRemoteHost()

  Returns:
    the hostname to which this transport is connected.

### getRemotePort

    int getRemotePort()

  Returns:
    the port number on the remote host to which this transport is connected.

### getServerVersion

    String getServerVersion()

  Returns the version string as sent by the SSH server for identification purposes, e.g. "OpenSSH_$version".

  If the transport has not yet been initialized via `init(java.lang.String, int, java.io.InputStream, java.io.OutputStream)`, it will be `null`.

  Returns:
    server's version string (may be `null`)

### getSessionID

    byte[] getSessionID()

  Returns:
    the session identifier assigned by server

### getService

    Service getService()

  Returns:
    the currently active `Service` instance.

### reqService

    void reqService(Service service)
                    throws TransportException

  Request a SSH service represented by a `Service` instance. A separate call to `setService(net.schmizz.sshj.Service)` is not needed.

  Parameters:
    `service` - the SSH service to be requested
  Throws:
    `TransportException` - if the request failed for any reason

### setService

    void setService(Service service)

  Sets the currently active `Service`. Handling of non-transport-layer packets is `delegated` to that service.

  For this method to be successful, at least one service request via `reqService(net.schmizz.sshj.Service)` must have been successful (not necessarily for the service being set).

  Parameters:
    `service` - (null-ok) the `Service`

### isAuthenticated

    boolean isAuthenticated()

  Returns:
    whether the transport thinks it is authenticated.

### setAuthenticated

    void setAuthenticated()

  Informs this transport that authentication has been completed. This method must be called after successful authentication, so that delayed compression may become effective if applicable.

### sendUnimplemented

    long sendUnimplemented()
                           throws TransportException

  Sends SSH_MSG_UNIMPLEMENTED in response to the last packet received.

  Returns:
    the sequence number of the packet sent
  Throws:
    `TransportException` - if an error occured sending the packet

### isRunning

    boolean isRunning()

  Returns:
    whether this transport is active.

    The transport is considered to be running if it has been initialized without error via `init(java.lang.String, int, java.io.InputStream, java.io.OutputStream)` and has not been disconnected.

### join

    void join()
              throws TransportException

  Joins the thread calling this method to the transport's death.

  Throws:
    `TransportException` - if the transport dies of an exception

### join

    void join(int timeout,
              TimeUnit unit)
              throws TransportException

  Joins the thread calling this method to the transport's death.

  Throws:
    `TransportException` - if the transport dies of an exception

### disconnect

    void disconnect()

  Send a disconnection packet with reason as `DisconnectReason.BY_APPLICATION`, and closes this transport.

### disconnect

    void disconnect(DisconnectReason reason)

  Send a disconnect packet with the given `reason`, and closes this transport.

  Parameters:
    `reason` - reason for disconnecting

### disconnect

    void disconnect(DisconnectReason reason,
                    String message)

  Send a disconnect packet with the given `reason` and `message`, and closes this transport.

  Parameters:
    `reason` - the reason code for this disconnect
    `message` - the text message

### write

    long write(SSHPacket payload)
               throws TransportException

  Write a packet over this transport.

  The `payload` `SSHPacket` should have 5 bytes free at the beginning to avoid a performance penalty associated with making space for header bytes (packet length, padding length).

  Parameters:
    `payload` - the `SSHPacket` containing data to send
  Returns:
    sequence number of the sent packet
  Throws:
    `TransportException` - if an error occurred sending the packet

### setDisconnectListener

    void setDisconnectListener(DisconnectListener listener)

  Specify a `listener` that will be notified upon disconnection.

  Parameters:
    `listener` -

### getDisconnectListener

    DisconnectListener getDisconnectListener()

  Returns:
    the current disconnect listener.

Copyright © 2009-2011. All Rights Reserved.