Threads in multi client-server application
I'm developing an on-line poker game for my uni project and need some guidance.
I have a server, which creates a new thread for each connected client. The server also hosts 3 tables and each client should be able to join any of them and play.So far I have something like this:
Server starts and listens for incoming connections.
Client connects and sends login details.
Server starts thread(T1) for the client.
T1 checks client's username and password.
if(not ok) => client tries again.
if(ok) => T1 continues to listen for client's input.
..and here I don't know what to do.Once connected the client should be able to browse the poker games and choose which one to join.So... do I need to use a separate thread on the client to maintain the connection to T1(see above) and then from that thread spawn another one which handles the poker game? Is it a good idea to have a thread start another one? Or do I start the thread, handling the table from the main client application process?
I hope I make sense...If something is unclear, please let me know and I'll try to clarify it and post any code if necessary.
PS: It's mostly about threads, so I thought it's better to post it here, not in networking
Re: Threads in multi client-server application
Create a separate thread for each client who approaches the server, and you don't need to spawn another thread from it, rather handle the entire game through it.(which includes client's and server's mutual information exchange, modification of game data etc) Maintain all the connection instances in a hashtable sort of thing.