Tcl
Tcl
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 Tcl Downloads
load ./chilkat.dll
set 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.
set tunnel [new_CkSshTunnel]
CkSshTunnel_put_DestHostname $tunnel "db.internal.example.com"
CkSshTunnel_put_DestPort $tunnel 5432
set sshPort 22
set success [CkSshTunnel_Connect $tunnel "ssh.example.com" $sshPort]
if {$success == 0} then {
puts [CkSshTunnel_lastErrorText $tunnel]
delete_CkSshTunnel $tunnel
exit
}
# 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.
set password "mySshPassword"
set success [CkSshTunnel_AuthenticatePw $tunnel "mySshLogin" $password]
if {$success == 0} then {
puts [CkSshTunnel_lastErrorText $tunnel]
delete_CkSshTunnel $tunnel
exit
}
set listenPort 1080
set success [CkSshTunnel_BeginAccepting $tunnel $listenPort]
if {$success == 0} then {
puts [CkSshTunnel_lastErrorText $tunnel]
delete_CkSshTunnel $tunnel
exit
}
# ... clients connect and transfer data ...
# Disconnect all current clients. The listener keeps running and will accept new clients.
set waitForThreads 1
set success [CkSshTunnel_DisconnectAllClients $tunnel $waitForThreads]
if {$success == 0} then {
puts [CkSshTunnel_lastErrorText $tunnel]
delete_CkSshTunnel $tunnel
exit
}
puts "All current clients disconnected; still accepting new ones."
set waitForThreadExit 1
set success [CkSshTunnel_CloseTunnel $tunnel $waitForThreadExit]
if {$success == 0} then {
puts [CkSshTunnel_lastErrorText $tunnel]
delete_CkSshTunnel $tunnel
exit
}
delete_CkSshTunnel $tunnel