Serversocket questions

Please excuse the noob-level questions but this is the first time I have worked with serversockets.

In the “server” app, the serversocket hands over the inbound connection to a TCPsocket. All fine thus far. Then

  1. If the client disconnects, the TCPsocket obviously gets an error. Does this cause the TCPsocket to close, or should one manually ( in code ) subsequently issue a close?
  2. How long do these TCPsockets stay around ( ie: after an error or a close ) or must one try to “nil” them? Really the question is how to clean up after the connection has gone.
  3. Do these TCPsockets in the array of TCPsockets get re-used, or will their “socket number” keep increasing?

Thanks

  1. If the other end of the connection disconnects then the TCPSocket will clean up the connection, set the LastErrorCode property to 102, and raise its Error event. You do not need to Close the socket unless you want to initiate the disconnect yourself.

  2. Objects in Xojo are reference counted, and are destroyed as soon as their refcount reaches 0. However, a connected TCPSocket will stay around until it disconnects, even if the refcount reaches 0. Once it disconnects (and if there are no more references) then the TCPSocket will be cleaned up automatically. A TCPSocket that is not connected will be cleaned up automatically as soon as its refcount reaches 0.

  3. Sockets in the ActiveConnections array are not reused.

Thank you so much for the excellent answers. :slight_smile: