comparison src/com/trilead/ssh2/LocalPortForwarder.java @ 0:0ce5cc452d02

initial version
author Carl Byington <carl@five-ten-sg.com>
date Thu, 22 May 2014 10:41:19 -0700
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:0ce5cc452d02
1
2 package com.trilead.ssh2;
3
4 import java.io.IOException;
5 import java.net.InetSocketAddress;
6
7 import com.trilead.ssh2.channel.ChannelManager;
8 import com.trilead.ssh2.channel.LocalAcceptThread;
9
10
11 /**
12 * A <code>LocalPortForwarder</code> forwards TCP/IP connections to a local
13 * port via the secure tunnel to another host (which may or may not be identical
14 * to the remote SSH-2 server). Checkout {@link Connection#createLocalPortForwarder(int, String, int)}
15 * on how to create one.
16 *
17 * @author Christian Plattner, plattner@trilead.com
18 * @version $Id: LocalPortForwarder.java,v 1.1 2007/10/15 12:49:56 cplattne Exp $
19 */
20 public class LocalPortForwarder {
21 ChannelManager cm;
22
23 String host_to_connect;
24
25 int port_to_connect;
26
27 LocalAcceptThread lat;
28
29 LocalPortForwarder(ChannelManager cm, int local_port, String host_to_connect, int port_to_connect)
30 throws IOException {
31 this.cm = cm;
32 this.host_to_connect = host_to_connect;
33 this.port_to_connect = port_to_connect;
34 lat = new LocalAcceptThread(cm, local_port, host_to_connect, port_to_connect);
35 lat.setDaemon(true);
36 lat.start();
37 }
38
39 LocalPortForwarder(ChannelManager cm, InetSocketAddress addr, String host_to_connect, int port_to_connect)
40 throws IOException {
41 this.cm = cm;
42 this.host_to_connect = host_to_connect;
43 this.port_to_connect = port_to_connect;
44 lat = new LocalAcceptThread(cm, addr, host_to_connect, port_to_connect);
45 lat.setDaemon(true);
46 lat.start();
47 }
48
49 /**
50 * Stop TCP/IP forwarding of newly arriving connections.
51 *
52 * @throws IOException
53 */
54 public void close() throws IOException {
55 lat.stopWorking();
56 }
57 }