Visual Basic 6.0
Visual Basic 6.0
Stop an SSH Tunnel Listener (StopAccepting)
See more SSH Tunnel Examples
Demonstrates the Chilkat SshTunnel.StopAccepting method, which stops the local listener so no new client connections are accepted. The only argument (waitForThread) selects whether to wait for the listener thread to exit. Existing forwarded clients remain connected.
Background: The distinction from
CloseTunnel is the point: StopAccepting closes only the front door, leaving already-connected clients to finish their transfers undisturbed. That makes it the graceful way to drain a tunnel — stop taking new work, let existing work complete, then close — rather than cutting everyone off at once.Chilkat Visual Basic 6.0 Downloads
Dim success As Long
success = 0
' Demonstrates the SshTunnel.StopAccepting method, which stops the local listener so that no new
' client connections are accepted. The only argument (waitForThread) selects whether to wait for
' the listener thread to exit. Existing forwarded clients remain connected.
Dim tunnel As New ChilkatSshTunnel
tunnel.DestHostname = "db.internal.example.com"
tunnel.DestPort = 5432
Dim sshPort As Long
sshPort = 22
success = tunnel.Connect("ssh.example.com",sshPort)
If (success = 0) Then
Debug.Print tunnel.LastErrorText
Exit Sub
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.
Dim password As String
password = "mySshPassword"
success = tunnel.AuthenticatePw("mySshLogin",password)
If (success = 0) Then
Debug.Print tunnel.LastErrorText
Exit Sub
End If
Dim listenPort As Long
listenPort = 1080
success = tunnel.BeginAccepting(listenPort)
If (success = 0) Then
Debug.Print tunnel.LastErrorText
Exit Sub
End If
' ... the tunnel runs for a while ...
' Stop accepting NEW connections, but leave already-connected clients running.
Dim waitForThread As Long
waitForThread = 1
success = tunnel.StopAccepting(waitForThread)
If (success = 0) Then
Debug.Print tunnel.LastErrorText
Exit Sub
End If
Debug.Print "The listener has stopped; existing clients continue."
Dim waitForThreadExit As Long
waitForThreadExit = 1
success = tunnel.CloseTunnel(waitForThreadExit)
If (success = 0) Then
Debug.Print tunnel.LastErrorText
Exit Sub
End If