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

## net.schmizz.sshj.connection.channel.direct
Class LocalPortForwarder

    java.lang.Object
      net.schmizz.sshj.connection.channel.direct.LocalPortForwarder

    public class LocalPortForwarder

extends Object

Constructor Summary
`LocalPortForwarder(Connection conn, SocketAddress listeningAddr, String host, int port)` Create a local port forwarder with specified binding (`listeningAddr`.
`LocalPortForwarder(ServerSocketFactory ssf, Connection conn, SocketAddress listeningAddr, String host, int port)` Create a local port forwarder with specified binding (`listeningAddr`.

Method Summary
`SocketAddress` `getListeningAddress()`
`void` `listen()` Start listening for incoming connections and forward to remote host as a channel.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### LocalPortForwarder

    public LocalPortForwarder(Connection conn,
                              SocketAddress listeningAddr,
                              String host,
                              int port)
                       throws IOException

  Create a local port forwarder with specified binding (`listeningAddr`. It does not, however, start listening unless `explicitly told to`. The `default` server socket factory is used.

  Parameters:
    `conn` - `Connection` implementation
    `listeningAddr` - `SocketAddress` this forwarder will listen on, if `null` then an ephemeral port and valid local address will be picked to bind the server socket
    `host` - what host the SSH server will further forward to
    `port` - port on `toHost`
  Throws:
    `IOException` - if there is an error binding on specified `listeningAddr`

### LocalPortForwarder

    public LocalPortForwarder(ServerSocketFactory ssf,
                              Connection conn,
                              SocketAddress listeningAddr,
                              String host,
                              int port)
                       throws IOException

  Create a local port forwarder with specified binding (`listeningAddr`. It does not, however, start listening unless `explicitly told to`.

  Parameters:
    `ssf` - factory to use for creating the server socket
    `conn` - `Connection` implementation
    `listeningAddr` - `SocketAddress` this forwarder will listen on, if `null` then an ephemeral port and valid local address will be picked to bind the server socket
    `host` - what host the SSH server will further forward to
    `port` - port on `toHost`
  Throws:
    `IOException` - if there is an error binding on specified `listeningAddr`

Method Detail

### getListeningAddress

    public SocketAddress getListeningAddress()

  Returns:
    the address to which this forwarder is bound for listening

### listen

    public void listen()
                throws IOException

  Start listening for incoming connections and forward to remote host as a channel.

  Throws:
    `IOException`

Copyright © 2009-2011. All Rights Reserved.