3
\$\begingroup\$

In a multiplayer JavaScript game client, is it a good idea to poll the server periodically to refresh online user list, or keep track of joined/left users? Is there a better option?

\$\endgroup\$
6
\$\begingroup\$

A combination of both strategies would likely yield the best results. Just keeping track of when user join/leave might not account for situations where the user is unexpectedly disconnected. A periodic poll would likely have to happen too often to get reasonably updated list of players joining and leaving.

So, update the list when a player joins or leaves and poll less periodically.

\$\endgroup\$
0
\$\begingroup\$

It depends is network traffic efficiency really important to you. If it is not you might have three actions in your server:

  • connect - which will add user to a server list
  • disconnect - which will delete user for a server list
  • poll - which will periodically check all users alive status (simple ping with client app)

More complex but also better way is to use timers. Every user will have a separate timer when he joins. When the timer runs out, server will poll for his status.

  • if he is alive server reset timer
  • if he is not responding server will delete him from user list

It won`t generate as big lag as polling all users at once.

Edit:

actions for the client

  • connect
  • disconnect
  • "ping" response

In other words, you are not polling server at all until server will ask you for alive status.

\$\endgroup\$
  • \$\begingroup\$ I am asking for the client, not the server side. My server side is a third party api. \$\endgroup\$ – eguneys Jan 23 '14 at 11:30

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.