Is there a way to keep a socket open until I close it? The socket seems to close after a while...
The answer is that Chilkat never takes a decision unto itself to close a socket. If you establish a TCP connection with a peer, unless your application specifically closes the connection, it will stay open -- assuming the peer does not take action to close the connection. (Note: TLS and SSH are just layers on top of TCP.)
A decision made by the connected peer (server) to close a connection entirely depends on the behavior of the server. For example, maybe it's an HTTP server that keeps a connection open after receiving a GET request, and then will decide after some period of inactivity to close the connection. The same can be said for FTP servers, email servers, SSH servers, etc., and the same can be said for any custom application acting as the peer in your connection.
But Chilkat never decides upon itself to just close a connection. The fact that Chilkat is an API (not an application) means that the behavior is under your control. (But of course, you cannot control the server's behavior.)