Jump to content
  • Advertisement
Sign in to follow this  
RenderMe

Designing Client-Server Games

This topic is 3322 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ok so I think I'm in a good place now for understanding TCP, UDP and multithreading I'm looking to put it all together. I have seen a design in the book: Core Techniques and Algorithms in Game Programming by Daniel Sánchez-Crespo Dalmau and he describes a design as follows:
Quote:
Server, step 1: Create socket, and bind to IP and port. Server, step 2: Listen, and wait in an accept call. Open "game lobby" and show IP/port. Server, step 3: Now the server is awaiting connections. Two threads/processes are required: an interface thread running the game menu interaction and another running the accept call so the system does not lock. Client, steps 1 to N: Open socket, and connect to the game server. Server, step 4: Update screen for each accepted connection. Implement the desired connection policy (connectionless iterative, connection-oriented concurrent). Server, steps N+1: At this point, all the clients are connected to the server. When the game menu interaction thread indicates a player has started the game, you can effectively close the main server socket, interrupt the accept call, and start the game with the connection sockets. The game server thus shuts down and accepts no further connections.
This has confused me a little in several places. Step 2 and 3 seem to contradict themselves. The way I understand, its saying accept a first client then create a lobby, then in step 3 it says create a thread/process for accepting clients and another for interface. The way I thought this system worked was to enter a loop accepting clients and creating a new thread/ process for each. Could someone shed some light on this confusion for me. Thank you!

Share this post


Link to post
Share on other sites
Advertisement
If that is the literal text from the game book, then the book sounds like it's garbage. You are correct; you only listen() in step 2 for the server.
Btw: you don't need two threads. If you select() on the listening socket, it will tell you whether you can accept() without blocking or not. You can do this (polling) in a WM_TIMER loop, every 50 milliseconds or so, for small-scale game servers, and it will work fine.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!