PowerBuilder
PowerBuilder
Disconnect All SSH Tunnel Clients
See more SSH Tunnel Examples
Demonstrates the Chilkat SshTunnel.DisconnectAllClients method, which disconnects all active tunnel clients while leaving the listener and SSH connection available. The only argument (waitForThreads) selects whether to wait for the client threads to exit.
Background: This is the complement of
StopAccepting: it clears out current clients but keeps accepting new ones, so the listener and SSH transport stay up. It is useful for forcibly resetting stuck or unwanted connections without tearing down the whole tunnel — for example, dropping all sessions before a maintenance action while leaving the tunnel ready to serve fresh connections immediately afterward.Chilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Tunnel
integer li_SshPort
string ls_Password
integer li_ListenPort
integer li_WaitForThreads
integer li_WaitForThreadExit
li_Success = 0
// Demonstrates the SshTunnel.DisconnectAllClients method, which disconnects all active tunnel
// clients while leaving the listener and SSH connection available. The only argument
// (waitForThreads) selects whether to wait for the client threads to exit.
loo_Tunnel = create oleobject
li_rc = loo_Tunnel.ConnectToNewObject("Chilkat.SshTunnel")
if li_rc < 0 then
destroy loo_Tunnel
MessageBox("Error","Connecting to COM object failed")
return
end if
loo_Tunnel.DestHostname = "db.internal.example.com"
loo_Tunnel.DestPort = 5432
li_SshPort = 22
li_Success = loo_Tunnel.Connect("ssh.example.com",li_SshPort)
if li_Success = 0 then
Write-Debug loo_Tunnel.LastErrorText
destroy loo_Tunnel
return
end if
// Normally you would not hard-code the password in source. You should instead obtain it
// from an interactive prompt, environment variable, or a secrets vault.
ls_Password = "mySshPassword"
li_Success = loo_Tunnel.AuthenticatePw("mySshLogin",ls_Password)
if li_Success = 0 then
Write-Debug loo_Tunnel.LastErrorText
destroy loo_Tunnel
return
end if
li_ListenPort = 1080
li_Success = loo_Tunnel.BeginAccepting(li_ListenPort)
if li_Success = 0 then
Write-Debug loo_Tunnel.LastErrorText
destroy loo_Tunnel
return
end if
// ... clients connect and transfer data ...
// Disconnect all current clients. The listener keeps running and will accept new clients.
li_WaitForThreads = 1
li_Success = loo_Tunnel.DisconnectAllClients(li_WaitForThreads)
if li_Success = 0 then
Write-Debug loo_Tunnel.LastErrorText
destroy loo_Tunnel
return
end if
Write-Debug "All current clients disconnected; still accepting new ones."
li_WaitForThreadExit = 1
li_Success = loo_Tunnel.CloseTunnel(li_WaitForThreadExit)
if li_Success = 0 then
Write-Debug loo_Tunnel.LastErrorText
destroy loo_Tunnel
return
end if
destroy loo_Tunnel