PowerBuilder
PowerBuilder
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 PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Ssh
integer li_Port
integer li_Connected
li_Success = 0
// Demonstrates how to check whether the connection to the SSH server still exists.
loo_Ssh = create oleobject
li_rc = loo_Ssh.ConnectToNewObject("Chilkat.Ssh")
if li_rc < 0 then
destroy loo_Ssh
MessageBox("Error","Connecting to COM object failed")
return
end if
li_Port = 22
li_Success = loo_Ssh.Connect("ssh.example.com",li_Port)
if li_Success = 0 then
Write-Debug loo_Ssh.LastErrorText
destroy loo_Ssh
return
end if
// IsConnected reports the state already known to the Ssh object. It does not perform a
// network round trip.
li_Connected = loo_Ssh.IsConnected
if li_Connected then
// 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.
li_Connected = loo_Ssh.SendIgnore()
end if
Write-Debug "connected = " + string(li_Connected)
loo_Ssh.Disconnect()
// After disconnecting, the object reports that it is no longer connected.
li_Connected = loo_Ssh.IsConnected
Write-Debug "connected = " + string(li_Connected)
destroy loo_Ssh