I'm planning to create a simple math multiplayer game and I plan to just use Ajax for the server/client communication but I'm not sure if this is sufficient or if I need a socket server.

The game will look like this:

  • 2-4 users
  • all get a simple math task (like: "37 + 14")
  • they have to solve it as fast as possible
  • first user who solves it is the winner

I will track the time for each user, since the game started, on the client side and everytime a user gives an answer, the answer and the passed time will be send to the server. Additionally I'll add a function which will check every 3 seconds if the other users finished, how much time they needed and who won.

Do you think this is possible just using Ajax? What alternatives are there?

  • 3
    \$\begingroup\$ It definitely is possible. From a design standpoint, I strongly recommend that you consider letting the server keep track of the time to prevent users from altering this on their end -- your users are going to have to login and identify themselves anyway, right? So you'll presumably use a cookie to differentiate them. \$\endgroup\$ Jun 19, 2011 at 15:37
  • \$\begingroup\$ For the first version I will keep it pretty simple, no cheat prevention etc. Just wanted to know if it is sufficient for a very first version (just want to see if it works and users like it). \$\endgroup\$ Jun 19, 2011 at 16:05
  • 1
    \$\begingroup\$ I wouldn't use the XML formatting part of AJAX, as it really isn't needed. \$\endgroup\$ Jun 19, 2011 at 16:17
  • \$\begingroup\$ @3nixios: Yup! Parsing plain/text is quite easy anyway, especially when you're the one deciding what data gets transferred. \$\endgroup\$ Jun 19, 2011 at 23:29

2 Answers 2


I think that Ajax is easily sufficient for this task.

The alternatives I can think of are:

  • 2
    \$\begingroup\$ Another great alternative is Java (specifically, a Java Applet). \$\endgroup\$ Jun 19, 2011 at 15:32
  • 4
    \$\begingroup\$ It would be a great alternative if we were in 1995. \$\endgroup\$
    – Raynos
    Jun 19, 2011 at 18:12
  • 1
    \$\begingroup\$ @Raynos: Thank you for pointing out that Java has such a long history -- the technologies that have stayed around have done so because they work well. I would say that for both Java and Flash, which each have significantly long histories, that they've both improved greatly over time; originally as web browser plug-ins these tools had their challenges (including performance problems), but now here we are ~16 years later with high-performance computing and technologies that grown to be much more versatile, smarter, and faster. \$\endgroup\$ Jun 19, 2011 at 23:38
  • 1
    \$\begingroup\$ @RandolfRichardson Could you show me a polished modern Java Applet which was designed to be used as an applet and not ported? (Recent popular Java Applets like minecraft were just ported as an applet because it was "free"). From the tools I've seen, applications written as Java Applets lacked a modern/polished look. \$\endgroup\$
    – Raynos
    Jun 20, 2011 at 5:50
  • \$\begingroup\$ I can't argue they're alternatives. But so is C++. C++0x is coming out soon too. Probably more versatile, smarter and faster. Probably no more helpful in this context as well. \$\endgroup\$
    – Rushyo
    Jun 22, 2011 at 12:33

Do you think this is possible just using Ajax? What alternatives are there?

Yes for the communication ajax is a valid channel to use.

But if by AJAX you mean sending single ajax requests using something like jQuery then no it's not a valid choice, merely because there are better options.

I highly recommend you use either

  • WebSockets and a range of fall-back techniques for older browsers
  • or COMET techniques.

For WebSockets I recommend you use an abstraction layer like socket.io (for node.js) or APE (for PHP).

Both of those use feature detection to use the best communication channel possible. This will pick WebSockets, COMET or a flash websocket bridge and those technologies support a wide range of browsers whilst still emulating a proper socket connection for you.

Arguably you can also use a SilverLight or Java websocket bridge but those are less common and not as well supported.

As for COMET the techniques are too highly integrated into the server-side stack/language to give generic advice.

If you need technology that interfaces well with a particular server side stack feel free to ask.

  • \$\begingroup\$ I thought about this but my managed server doesn't support sockets. Is it possible to rent a virtual server for around 10 Dollar/month or do I need a full server (I have no experience with sockets at all)? \$\endgroup\$ Jun 21, 2011 at 8:27
  • 1
    \$\begingroup\$ @ChristianStrang that's interesting, You can use an external service like pusher. Are you sure you can't just install node.js or APE on your managed server? \$\endgroup\$
    – Raynos
    Jun 21, 2011 at 8:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .