Delphi DLL
Delphi DLL
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 Delphi DLL Downloads
var
success: Boolean;
tunnel: HCkSshTunnel;
sshPort: Integer;
password: PWideChar;
listenPort: Integer;
waitForThreads: Boolean;
waitForThreadExit: Boolean;
begin
success := False;
// 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.
tunnel := CkSshTunnel_Create();
CkSshTunnel_putDestHostname(tunnel,'db.internal.example.com');
CkSshTunnel_putDestPort(tunnel,5432);
sshPort := 22;
success := CkSshTunnel_Connect(tunnel,'ssh.example.com',sshPort);
if (success = False) then
begin
Memo1.Lines.Add(CkSshTunnel__lastErrorText(tunnel));
Exit;
end;
// 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.
password := 'mySshPassword';
success := CkSshTunnel_AuthenticatePw(tunnel,'mySshLogin',password);
if (success = False) then
begin
Memo1.Lines.Add(CkSshTunnel__lastErrorText(tunnel));
Exit;
end;
listenPort := 1080;
success := CkSshTunnel_BeginAccepting(tunnel,listenPort);
if (success = False) then
begin
Memo1.Lines.Add(CkSshTunnel__lastErrorText(tunnel));
Exit;
end;
// ... clients connect and transfer data ...
// Disconnect all current clients. The listener keeps running and will accept new clients.
waitForThreads := True;
success := CkSshTunnel_DisconnectAllClients(tunnel,waitForThreads);
if (success = False) then
begin
Memo1.Lines.Add(CkSshTunnel__lastErrorText(tunnel));
Exit;
end;
Memo1.Lines.Add('All current clients disconnected; still accepting new ones.');
waitForThreadExit := True;
success := CkSshTunnel_CloseTunnel(tunnel,waitForThreadExit);
if (success = False) then
begin
Memo1.Lines.Add(CkSshTunnel__lastErrorText(tunnel));
Exit;
end;
CkSshTunnel_Dispose(tunnel);