What is the best way to keep track of a network client when writing a simple two player game server (checkers, tic-tac-toe, etc.) Should I assign a number to each client as soon as they connect to the server? Should I try to recycle the numbers at some point? Perhaps their is a better way I'm not thinking of... Thanks, Drew
posted 14 years ago
Use one of the precepts of Object Orientation: identity. Keep a Set (or Map) of client objects on the server. When a client connects add it to the Set, when it disconnects remove it from the Set.
Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher