Archived Forum Post

Index of archived forum posts

Question:

BeginAccepting is successful even if destination host:port is invalid?

Sep 27 '12 at 13:41

I developed a sshtunnel application for my office with CHILKATSSHLib_TLB. But it fails data communication after few minutes every time. i could not find the reason therefore i coded a simple tunnel application to test. and I found that even without connecting to the real sshtunnel success := sshTunnel.BeginAccepting(listenPort); sends messages as tunnel connecting is success

MESSAGES i gets from my test application with delphi xe3 (and delphi 7)

  1. Tunnel OK
ChilkatLog:
  BeginAccepting:
    DllDate: Aug  5 2012
    UnlockPrefix: 30-day trial
    Username: xxxx
    Architecture: Little Endian; 32-bit
    Language: ActiveX
    VerboseLogging: 0
    listenPort: 3316
    destPort: 1433
    destHostname: myDbServer11111.com
    acceptThreadSessionLogPath:
    Listen thread started.
    Success.
  --BeginAccepting
--ChilkatLog

Result = 1

note
there is no server called myDbServer11111.com
there is no server called '192.111.1.111'

so how it does show as Success?


Answer

The reason BeginAccepting is successful is because no connection to the destination host:port happens during the BeginAccepting method call.

The BeginAccepting method starts a background thread that will begin accepting incoming connections on the localhost:listenPort. BeginAccepting returns success if the background thread is started, the socket created, and the background thread has begun listening on the listenPort.

At some future point in time, an incoming connection to listenPort might arrive. The background thread accepts it and establishes a connection to the SSH server host:port (not the destination host:port). SSH port forwarding is setup so that data sent to the SSH server is then forwarded (by the SSH server) to the destination host:port, which in your case is myDbServ11111.com.

Note that even when an SSH tunnel is established, it is not your app's background thread that is connected to the destination host:port, it is the SSH server that makes this connection.