How to properly close a TCP listener in a Console EasyTCP Server app?

Hello All,

I am working on a Linux Console TCP Server app. It uses EasyTCP. What is the best practice for closing a listener object following a disconnection? I want to be sure that the DB is closed, and the current listener object is killed, leaving only other [new] listeners are running.

Thanks,
Tim

If you have multiple listeners, you should consider a ServerSocket.

Hi Dean,
There is a ServerSocket. It spawns a number of listeners.
Tim

The remote side should say “goodbye” before disconnecting. Otherwise, you may not know they went away. Bake it into your protocol.

Hi Tim.
It does that already. The listener does not disconnect, unless a long timeout occurs. It is after the disconnect that I am looking to get right.

Call whatever cleanup code you use when the remote side hangs up, then close the socket.

Is the Listener socket closed from within itself, or the ServerSocket?

Good point. Since the serversocket owns the listener, it may be best to Disconnect the socket instead of Closing it. That will trigger an error event and alert the serversocket to clean up the socket and dispose of it.

Hi Tim,
I am missing something here. The client side disconnects from the ServerSocket/Listener. Once that is done the database needs to be closed, along with any other house cleaning that I have created. So once that is done, how do I tell the ServerSocket to do its clean up of the now not used Listener?

Tim

You don’t have to “tell” the serversocket. It handles that for you. But you don’t have any control over the when and how, so the client side must tell you that its about to disconnect, so you can close the database, etc, before it actually disconnects. I wouldn’t rely on the Error event to do this.

Ahhhh… I see. I believe I am using the error event to trigger the close etc.
Thanks for the clarity Tim,
Tim