Java Ganymed ssh tunnelling... How to check that a tunnel is still open?

1k views Asked by At

I have an ssh tunnel created with Ganymed's LocalPortForwarder class. It's working fine. The question is how (programmatically in Java) do I check that the tunnel is still open and active?

For reference, here's the code snippet that creates the tunnel (error checking removed for brevity's sake):

Connection conn = new Connection(remoteHostName);

conn.connect();

boolean isAuthenticated = conn.authenticateWithPassword(username, password);

LocalPortForwarder lpf1
               = conn.createLocalPortForwarder(newPort,
                                               remoteHostName, 
                                               Integer.parseInt(remoteHostPort));
1

There are 1 answers

0
user207421 On

The only way to detect the state of any TCP connection is to try to use it. It doesn't have a 'heartbeat' like SNA used to.