I'm writing an HTML5 game that takes place in a single screen and does not have any data that would need to be saved (except for a score). I am writing all of my canvas logic on the front end. because it seemed like the easiest way to program interactions. However Ive been reading on r/gamedev that the best way to organize games is to sent client input to the server and have the server render the results on the client. I have a couple questions about this:

1.) If my game takes place on a single screen (meaning no changes in background, enemies, etc. Think Space Invaders), is it worth putting my game logic on the server?

2.)If I do put my logic on the server, how can i facilitate clean communication with the client? Web sockets? or plain HTTP? Using a WebSocket seems straightforward for this kind of task, but they are not supported by all browsers. On the flip side I'm kind of hazy on how HTTP could be used to send and receive data from the client.

Any advice would be great.

  • 1
    \$\begingroup\$ Usually when people are talking about client/server they are talking about multiplayer games. I don't generally think of space invaders as multiplayer, however. Is this just a single player game? \$\endgroup\$ – Cameron Fredman Feb 26 '13 at 18:55

Generally, this advice is given not because of abstraction or code cleanliness but rather because gameplay logic that is sensitive must be simulated by an authorative server to prevent cheating and hacking. Long story short: If you don't particularly care about players hacking their score - don't bother.

If your game is multiplayer, then you should looking into making the client nothing but a "dumb terminal" and display for the game. Generally, this involves the client only sending inputs and actions to the server, and the server sends the results back to the entities that may be interested in his result. You can look at this article for getting started with socket.io.

It's a broad topic and tough to cover in this answer but the gist of the idea is that. For example, instead of just moving and telling every other player "I got 100 points"... you instead send "I shot", and the server simulates your shot. Then, when the server sees someone was "shot" then it sends a result back to all other players who may be interested that this object was shot, so something can explode, the killer can get points etc.

  • \$\begingroup\$ So basically, the client should be treated as a dumb terminal that accepts server input? Any advice on how to accomplish this using http requests? \$\endgroup\$ – codeninja Feb 26 '13 at 18:32
  • \$\begingroup\$ This is only the case if your game is going to be multiplayer - is your game singleplayer? If not, then just leave it as is. If it's supposed to be multiplayer, there's a lot of reading you're going to want to do. \$\endgroup\$ – Vaughan Hilts Feb 26 '13 at 18:38
  • \$\begingroup\$ if you could forward me to some resources it would be awesome =D \$\endgroup\$ – codeninja Feb 26 '13 at 18:47
  • \$\begingroup\$ Added more information. \$\endgroup\$ – Vaughan Hilts Feb 26 '13 at 19:02
  • 1
    \$\begingroup\$ You could maybe use ajax, but straight HTTP requests would not work. \$\endgroup\$ – aglassman Feb 26 '13 at 22:10

it depends on what game you're trying to make and do you care about cheating in your game.

if you don't care about cheating, it will be much more easier to just do everything on client and simply relay the actions/results via the server to other clients.

if you do care about anti-cheating, and depending on game type, you might want to make some predictions on client side so that your game dont suffer from round-tip delay. in short, your client need to have the logic and also send the actions to the server to be simulated, but your client will only trust the results from the server.


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.