0
\$\begingroup\$

My game server currently launches a thread for each connected client, and handles all data exchange through that socket in a server-blocks-until-client-requests fashion. The problem derives from the blocking, since sometimes the client state should be updated upon server demand without a previous request from the client, which is incompatible with a blocking state.

I have done some research and come up to the next possibilities:

1) Open a second connection to the client, which will only be used for sending data to the client so it can update its state.

2) Use of non-blocking sockets.

3) Use of asynchronous server.

What is the most common design to tackle this particular problem?


2 and 3 seen in https://stackoverflow.com/questions/3895461/non-blocking-sockets

\$\endgroup\$
  • \$\begingroup\$ This choice depends on too many things to have a canonical answer. \$\endgroup\$ – Almo Apr 17 at 19:11
  • \$\begingroup\$ @Almo Your comment contributes absolutely nothing beyond the fact of pointing out that you know what all those "too many things" are. \$\endgroup\$ – roymcclure Apr 18 at 9:15
  • \$\begingroup\$ This site is for questions with canonical answers. It's not for discussions or laundry lists of stuff. \$\endgroup\$ – Almo Apr 20 at 0:43
  • 1
    \$\begingroup\$ "What is the most common design to tackle this particular problem?" is unanswerable without a polling a huge ton of developers. You show three possibilities... why not use one of these? What is specific about your game that precludes using one of them? In its current form we really can't help much, because "which solution is most common" isn't really that relevant. \$\endgroup\$ – Almo Apr 20 at 13:29
  • 1
    \$\begingroup\$ I have to agree with Almo. "What is most common" isn't relevant. It's offloading consideration of your project's needs on the shaky assumption that all games are the same, so whatever is "common" must therefore be "right for this project." I think you should question that premise. Test the solutions you've proposed so far against your own project's needs as the razor: would solution n work for your case? If it looks like it could, try it! If you run into a problem applying it to your case, ask how to fix that specific problem, or try one of your other proposed solutions. \$\endgroup\$ – DMGregory Apr 20 at 17:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.