tags:

views:

451

answers:

2

Hi,

I'm running an application on a bunch of nodes in a class A network, but can only access them from my own system if I log into the only node in that network that also has a class B address.

However, the client portion (with the GUI and everything) can run only on my system, so I need some way of communicating with the class A network. The client (my system) attempts to set up a simple TCP socket to the server (at the edge of the internal network, with a ServerSocket), but gets a Connection Timed Out exception. Since only the SSH port 22 is open, someone recommended I use SSH tunneling to send packets from my system to the internal network.

After a bit of Googling, I see that the following allows you to set up an SSH tunnel, but how would I use this from within Java to set up the sockets and what not? Thanks!

ssh -L 2222:10.10.10.10:22 174.174.174.174

EDIT: I have used JSch to set up port forwarding from my system to an internal node, but is there any way I can make it bidirectional without having to set up a separate tunnel on every internal node? (The nodes aren't using the same TCP connection to respond, but have set up new connections to my laptop's port 2222.)

+2  A: 

SSL Tunnel works just like any other socket, you just need to connect to the local socket. In your case, it's,

Socket socket = new Socket("localhost", 2222);
OutputStream out = socket.getOutputStream();

The tunnel will actually make a connection to 10.10.10.10:22.

ZZ Coder
I believe you mean "SSH", not "SSL" ;-).
Matt Solnit
A: 

If you're asking how to programatically set up the forwarded ports, use JSch which supports port forwarding.

Lispnik
Yes, that's exactly what I need to do. I've put up an excerpt of the code I'm trying out to make the connection, but so far I'm still getting Connection Timed Out exceptions.
thodinc