DataFlex
DataFlex
Check the SSH Connection (IsConnected)
See more SSH Examples
Demonstrates how to check whether the connection to the SSH server still exists. The IsConnected property is checked first, and SendIgnore is then used to confirm the link for certain.
Background: These checks differ in strength.
IsConnected simply reports the state the object already knows and involves no network activity, so it can stay true after a silent network failure the operating system has not yet noticed. SendIgnore sends an SSH IGNORE message — discarded by the peer by design — which exercises the real write path and is therefore much stronger evidence the link is usable. CheckConnection sits between the two, peeking at the socket without sending anything.Chilkat DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoSsh
Integer iPort
Boolean iConnected
String sTemp1
Move False To iSuccess
// Demonstrates how to check whether the connection to the SSH server still exists.
Get Create (RefClass(cComChilkatSsh)) To hoSsh
If (Not(IsComObjectCreated(hoSsh))) Begin
Send CreateComObject of hoSsh
End
Move 22 To iPort
Get ComConnect Of hoSsh "ssh.example.com" iPort To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoSsh To sTemp1
Showln sTemp1
Procedure_Return
End
// IsConnected reports the state already known to the Ssh object. It does not perform a
// network round trip.
Get ComIsConnected Of hoSsh To iConnected
If (iConnected) Begin
// Verify for certain by sending an SSH IGNORE message, which exercises the actual write
// path. The server sends no reply, but a successful send proves the link is writable.
Get ComSendIgnore Of hoSsh To iConnected
End
Showln "connected = " iConnected
Send ComDisconnect To hoSsh
// After disconnecting, the object reports that it is no longer connected.
Get ComIsConnected Of hoSsh To iConnected
Showln "connected = " iConnected
End_Procedure