KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ch > ethz > ssh2 > LocalPortForwarder


1
2 package ch.ethz.ssh2;
3
4 import java.io.IOException JavaDoc;
5 import java.net.InetSocketAddress JavaDoc;
6
7 import ch.ethz.ssh2.channel.ChannelManager;
8 import ch.ethz.ssh2.channel.LocalAcceptThread;
9
10 /**
11  * A <code>LocalPortForwarder</code> forwards TCP/IP connections to a local
12  * port via the secure tunnel to another host (which may or may not be identical
13  * to the remote SSH-2 server). Checkout {@link Connection#createLocalPortForwarder(int, String, int)}
14  * on how to create one.
15  *
16  * @author Christian Plattner, plattner@inf.ethz.ch
17  * @version $Id: LocalPortForwarder.java,v 1.6 2006/10/20 20:50:24 cplattne Exp $
18  */

19 public class LocalPortForwarder
20 {
21     ChannelManager cm;
22
23     String JavaDoc host_to_connect;
24
25     int port_to_connect;
26
27     LocalAcceptThread lat;
28
29     LocalPortForwarder(ChannelManager cm, int local_port, String JavaDoc host_to_connect, int port_to_connect)
30             throws IOException JavaDoc
31     {
32         this.cm = cm;
33         this.host_to_connect = host_to_connect;
34         this.port_to_connect = port_to_connect;
35
36         lat = new LocalAcceptThread(cm, local_port, host_to_connect, port_to_connect);
37         lat.setDaemon(true);
38         lat.start();
39     }
40
41     LocalPortForwarder(ChannelManager cm, InetSocketAddress JavaDoc addr, String JavaDoc host_to_connect, int port_to_connect)
42             throws IOException JavaDoc
43     {
44         this.cm = cm;
45         this.host_to_connect = host_to_connect;
46         this.port_to_connect = port_to_connect;
47
48         lat = new LocalAcceptThread(cm, addr, host_to_connect, port_to_connect);
49         lat.setDaemon(true);
50         lat.start();
51     }
52
53     /**
54      * Stop TCP/IP forwarding of newly arriving connections.
55      *
56      * @throws IOException
57      */

58     public void close() throws IOException JavaDoc
59     {
60         lat.stopWorking();
61     }
62 }
63
Popular Tags