I’m writing a socket server designed to only host a small number of client connections.
When a user attempts connection, my server could do one of two things, AFAICT:
- accept() the incoming socket connection, inform the user that the server is full, then close() the connection;
- Simply ignore the attempt to connect, if the connections list is full.
I don’t really like the second option, but it seems to me that the first invites trouble, where players (since this is a game) may try to hammer the server. Whereas if I simply ignore the attempts, there cannot be any problem in this regard.
What approach should I take?
I’d say inform the client.
Hammering won’t take down a server if it isn’t a (or several) program(s) that hammers like crazy, opening lots of connections in parallel and really trying.
Let the user click on a button to connect and if the server is full, wait a second (or more) and then let the player retry, that way the client (the player) will be happy (he’s in control) and he can’t hammer more than like once a second (and who is going to sit and hammer manually for hours anyway).