Re: HELP: Java ssh library - unstable connection
On Jul 4, 11:47 am, Nigel Wade <n...@ion.le.ac.uk> wrote:
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
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
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
their Socket. If the other end has simply "disappeared", due to network
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
This is actually a good thing in general, although in your particular
you might not agree.
If the host at the other end was shutdown cleanly then the remote end ought
have closed the socket rather than just terminating, which shouldn't
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.
Thanks for your thorough response!
Unfortunately, com.sshtools.j2ssh is a free Library which is no longer
supported and the documentation it has is barebones (The only
documentation of isConnected() is that it returns a boolean value and
not the meaning of this value).
Ah, software without documentation. Pretty much useless then. If you guess at
what isConnected() does, and assume it's the same as Socket.isConnected() it
won't tell you what you want to know. isConnected() only tells you if the
Socket has been connected, not whether it is currently connected. Basically
isConnected() returns false *before* a connection is established, it returns
true thereafter regardless of the state.
It does seem as if the read and write operations hang, but the hang
does get timed out. This is not the case with disconnect which simply
hangs (seemingly forever!)
How long is forever? TCP/IP will timeout in around 2 hours by default, IIRC.
No, unfortunately, but I think you can reduce the timeout. If you do have to
shut the machine down make sure you do it correctly so the server application
gets a chance to close its sockets. This might help to avoid the timeout.
Although this does depend on the OS and how it handles its shutdown procedure,
and how your server handles notification from the OS (if it receives any) that
it needs to shutdown. Other than that, don't keep rebooting the server.
It really is a good thing. Imagine what would happen if your connection got
reset every time there was a temporary break in the network anywhere between
the client and its server? Not just for you, but for every socket in use on the
Internet. The recovery code necessary in every single application would be
horrendous, and the probability of it all actually working would be negligible.
Nigel Wade, System Administrator, Space Plasma Physics Group,
University of Leicester, Leicester, LE1 7RH, UK
E-mail : firstname.lastname@example.org
Phone : +44 (0)116 2523548, Fax : +44 (0)116 2523555