Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Network Clients  RSS feed

 
Drew Lane
Ranch Hand
Posts: 296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!