*** the server has shut down the ssh connection
To reproduce:
1. Create a connection (eg using SftpClient)
2. Kill sshd process on server.
3. Inspect value of IsConnected property.
*** the network is no longer available
To reproduce:
1. Create a connection (eg using SftpClient)
2. Unplug network cable
3. Inspect value of IsConnected property.
I can reproduce this with ssh.net built from SVN/TFS.
Comments: ** Comment from web user: drieseng **
The fact that IsConnected returns true in the above cases also causes issues when disconnecting or disposing the client.
For example:
https://sshnet.codeplex.com/workitem/1581
Note that I have yet to find an easy way to tell whether the connection is in one of the states mentioned above. Socket.Poll does not offer a solution, and neither does Socket.Send with a empty buffer.
The Socket.Connected property only allows you to check whether a socket is NOT connected. If it returns false, you can be sure that the connection is closed (or not yet opened). When it returns true, you only know that the last operation was succesful.
Even sending an "IgnoreMessage" is considered successful while the network cable is unplugged.
From the MSDN docs:
"There is also no guarantee that the data you send will appear on the network immediately. To increase network efficiency, the underlying system may delay transmission until a significant amount of out-going data is collected. A successful completion of the Send method means that the underlying system has had room to buffer your data for a network send."