Do you ever need to close a EasyTCPSocket?

I am building a client-server system where the client sends SQL commands to the server via an EasyTCPSocket, and the server runs the SQL and returns the RecordSet. It is working well.

Given that there may be gaps of a few minutes (or longer) between client conversations with the server:

  1. should I get the client to Close the EasyTCPSocket after each use?
  2. If I don’t close the EasyTCPSocket, will it reuse the same EasyTCPSocket on next connection or create a new one, clogging up the server until they timeout?
  3. If I don’t close the EasyTCPSocket, will the max socket connections be reached quickly if lots of Xojo clients are connecting (assuming the number of clients is less than MaximumSocketsConnected)?
  4. Is there a problem if I DO close the EasyTCPSocket after each use, other than the delay time to re-connect?

I am erring on the side of closing the EasyTCPSocket so the server load will be minimised and can support more clients. Am I wrong? The clients will never be really ‘chatty’, talking at most once per minute.

Starting TCP connections takes a bit so better to keep them open.

If you reuse the same EasyTCPSocket object then it will use the same connection assuming it is still connected.

Yeah, just keep them open. A non active (but connected) TCP connection won’t heavy on your system load.

I have done what you’ve suggested (not close the EasyTCPSocket) and it is working faster (obviously).

Am I correct in assuming that:

  1. as clients quit/disconnect that the EasyTCPSocket will go back into the pool immediately?
  2. with the EasyTCPSockets now permanently open during a client session, the number of clients that I can support is essentially MaximumSocketsConnected (since they are never disconnect during a session)?
  1. There is no pool unless you specifically created a pool. Pools are generally used to maintain a number of connections that can be re-used once they are done doing whatever they needed. I believe what you mean is does the port become available once the connection is disconnected. Yes it does. However that does not necessarily mean the server is still listening.

  2. Available memory, operating system configuration, etc. There is a finite number of ports and connections you can maintain at any one time. From Wikipedia “A port number is a 16-bit unsigned integer, thus ranging from 0 to 65535”. You may want to read about ServerSocket to make listening and responding to connections easier.

Regarding #2, if MaximumSocketsConnected is set to 200, will the 201st simultaneous client be rejected?

Yes, it should.

Thank you Phillip and Mathias!