Re: HELP: Java ssh library - unstable connection
Yaneeve wrote:
I am using the com.sshtools.j2ssh.SshClient class in order to connect
to a remote machine. Once the remote machine is rebooted this class
does not recognize the fact that it is no longer connected (in other
words: isConnected() returns an answer of true) trying to disconnect
the connection at this stage (invocation of disconnect()) causes my
program to hang! Since this is a free and no longer supported library,
I fear that it is not I that am doing anything wrong but the ssh
library. Does anybody recognize this behavior? If so I would
appreciate a proposed solution. On the other hand I would even more
appreciate a recommendation for another (MORE STABLE) ssh/sftp library!
What does the documentation say is the meaning of the return value of
isConnected()? If it's the same as Socket() then it's not what you are assuming
it to mean. In this case the ssh library would be behaving correctly and it
would be you that was doing something wrong.
An application which has a Socket open does not get informed that the other end
has closed its end, or gone away. The only way to find out is via the normal
data transfer mechanism. A read or write will fail if the other end has closed
their Socket. If the other end has simply "disappeared", due to network failure
or a system reboot for example, then the read/write will hang until the
specified timeout period elapses. Normal shutdown of a Socket requires a
bi-directional flow of packets so it will also hang if one end has disappeared.
This is actually a good thing in general, although in your particular instance
you might not agree.
If the host at the other end was shutdown cleanly then the remote end ought to
have closed the socket rather than just terminating, which shouldn't resulOnly
ant in a hang at your end. However, this is not guaranteed and some OS's are
worse than others in this regard.
This is a fact of life, it's how TCP/IP works, and ssh uses TCP/IP.
--
Nigel Wade, System Administrator, Space Plasma Physics Group,
University of Leicester, Leicester, LE1 7RH, UK
E-mail : nmw@ion.le.ac.uk
Phone : +44 (0)116 2523548, Fax : +44 (0)116 2523555