I’m currently writing a multi-process network game server (one gatekeeper process which tells players what games are currently running and allows them to create and join games, and a process per game instance).
In which cases it would be useful for the gatekeeper to drop TCP connection to the client, and in which cases it should continue listening? E.g. should the gatekeeper close the connection after the client has successfully joined a game, or retrieved a list of games, or when an error occurs (such as there are no free slots in the game he’s trying to join). Or should the connection close on a timeout? Thanks.
The simplest protocols often use a separate connection for every separate transaction. Web browsers, in their simplest mode of operation, would just connect to download a page and then disconnect. But connecting and disconnecting repeatedly to the same server does carry an overhead, so it is also possible to reuse an existing connection.
On the other hand, if there will be long delays between uses of the connection, and there are large numbers of clients, you have to consider the limited number of simultaneous connections that the server can manage. This is where an inactivity timeout may be useful.
Keeping a connection open also allows you to do asynchronous notification from server to client, without the client needing to be outside a firewall. The client connects and then holds the connection, constantly reading from it. The server sends notifications via the connection.