views:

48

answers:

1

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));

A: 

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.

EJP