Somewhat of a general question but I’m new at this. I have a client applet and a server application set up. It uses TCP sockets and works pretty well.
This is an outline of the server architechture:
main class creates a server thread that loops on serversocket and accepts new clients making an object out of each and adding them to a concurrentLinkedQueue of waiting players.
main class also creates a thread that continually checks the queue of waiting players and once two are connected creates a game object out of the two players.
each client is a new thread that loops on the in-stream of that client.
each game object is also a thread that handles protocol back and forth between the clients during game play.
as i said before it works pretty well as is but I have two questions:
- I’m worried that I am creating too many threads and the server may crash if it has to handle a lot of players. is the architecture i have set up a solid one or is there a better aproach?
- Whats a good way to track whether or not a client is still connected? clients close their browsers and reload etc. from a server back end stand point i dont need to be manipulating client objects that no longer exist.
hopefully i explained myself pretty well but essentially i just need some guidance on the general set up of a server designed to handle many clients and many games going on at one time.