Xojo Plugin
Xojo Plugin
SSH Tunnel Timeouts and IP Preference
See more SSH Tunnel Examples
Demonstrates the ConnectTimeoutMs, IdleTimeoutMs, and PreferIpv6 properties, which govern how long the tunnel waits to connect and to transfer data, and which IP version it prefers.
Background:
ConnectTimeoutMs bounds how long a connection attempt blocks — important so an unreachable server fails promptly instead of hanging — while IdleTimeoutMs guards against a stalled transfer holding a connection open indefinitely. PreferIpv6 only matters when a hostname resolves to both address families, choosing which to try first; the default prefers IPv4.Chilkat Xojo Plugin Downloads
Dim success As Boolean
success = False
// Demonstrates the SshTunnel connection-behavior properties ConnectTimeoutMs, IdleTimeoutMs, and
// PreferIpv6.
Dim tunnel As New Chilkat.SshTunnel
// Maximum time to establish the SSH connection (default 30000 ms).
tunnel.ConnectTimeoutMs = 10000
// Stall timeout for tunnel data-transfer operations (default 30000 ms).
tunnel.IdleTimeoutMs = 15000
// When a hostname resolves to both IPv4 and IPv6, prefer IPv6. The default (0) prefers IPv4.
tunnel.PreferIpv6 = True
tunnel.DestHostname = "db.internal.example.com"
tunnel.DestPort = 5432
Dim sshPort As Int32
sshPort = 22
success = tunnel.Connect("ssh.example.com",sshPort)
If (success = False) Then
System.DebugLog(tunnel.LastErrorText)
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.
Dim password As String
password = "mySshPassword"
success = tunnel.AuthenticatePw("mySshLogin",password)
If (success = False) Then
System.DebugLog(tunnel.LastErrorText)
Return
End If
Dim listenPort As Int32
listenPort = 1080
success = tunnel.BeginAccepting(listenPort)
If (success = False) Then
System.DebugLog(tunnel.LastErrorText)
Return
End If
System.DebugLog("Tunnel established.")
Dim waitForThreadExit As Boolean
waitForThreadExit = True
success = tunnel.CloseTunnel(waitForThreadExit)
If (success = False) Then
System.DebugLog(tunnel.LastErrorText)
Return
End If