comparison src/ch/ethz/ssh2/LocalPortForwarder.java @ 273:91a31873c42a ganymed

start conversion from trilead to ganymed
author Carl Byington <carl@five-ten-sg.com>
date Fri, 18 Jul 2014 11:21:46 -0700
parents
children 071eccdff8ea
comparison
equal deleted inserted replaced
272:ce2f4e397703 273:91a31873c42a
1 /*
2 * Copyright (c) 2006-2013 Christian Plattner. All rights reserved.
3 * Please refer to the LICENSE.txt for licensing details.
4 */
5
6 package ch.ethz.ssh2;
7
8 import java.io.IOException;
9 import java.net.InetSocketAddress;
10 import java.net.ServerSocket;
11
12 import ch.ethz.ssh2.channel.ChannelManager;
13 import ch.ethz.ssh2.channel.LocalAcceptThread;
14
15 /**
16 * A <code>LocalPortForwarder</code> forwards TCP/IP connections to a local
17 * port via the secure tunnel to another host (which may or may not be identical
18 * to the remote SSH-2 server). Checkout {@link Connection#createLocalPortForwarder(int, String, int)}
19 * on how to create one.
20 *
21 * @author Christian Plattner
22 * @version 2.50, 03/15/10
23 */
24 public class LocalPortForwarder
25 {
26 final ChannelManager cm;
27
28 final String host_to_connect;
29
30 final int port_to_connect;
31
32 final LocalAcceptThread lat;
33
34 LocalPortForwarder(ChannelManager cm, int local_port, String host_to_connect, int port_to_connect)
35 throws IOException
36 {
37 this.cm = cm;
38 this.host_to_connect = host_to_connect;
39 this.port_to_connect = port_to_connect;
40
41 lat = new LocalAcceptThread(cm, local_port, host_to_connect, port_to_connect);
42 lat.setDaemon(true);
43 lat.start();
44 }
45
46 LocalPortForwarder(ChannelManager cm, InetSocketAddress addr, String host_to_connect, int port_to_connect)
47 throws IOException
48 {
49 this.cm = cm;
50 this.host_to_connect = host_to_connect;
51 this.port_to_connect = port_to_connect;
52
53 lat = new LocalAcceptThread(cm, addr, host_to_connect, port_to_connect);
54 lat.setDaemon(true);
55 lat.start();
56 }
57
58 /**
59 * Return the local socket address of the {@link ServerSocket} used to accept connections.
60 * @return
61 */
62 public InetSocketAddress getLocalSocketAddress()
63 {
64 return (InetSocketAddress) lat.getServerSocket().getLocalSocketAddress();
65 }
66
67 /**
68 * Stop TCP/IP forwarding of newly arriving connections.
69 *
70 * @throws IOException
71 */
72 public void close() throws IOException
73 {
74 lat.stopWorking();
75 }
76 }