Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which one should I choose AMQP or XMPP for real-time browser-based game?

I'm choosing between AMQP (RabbitMQ) vs XMPP (eJabberd) for my browser-based flash-free javascript powered real-time turn-based game. I don't know much about AMQP and XMPP protocol. I would like to use PHP for user-authorization and some data store-retrieve with MySQL. As far as I found out, RabbitMQ has PHP clients but eJabberd not.

What I understood is javascript client calls PHP script and manipulate necessary processing and then pass to AMQP or XMPP server to pass the data to opponent player. There is a good book 'Pro XMPP Programming with JS and jQuery' from Wrox but there is no example with PHP. So following are my questions.

1) Which protocol is suit for my game?

2) Shall I choose RabbitMQ just for it's PHP client support?

like image 787
Devyn Avatar asked May 30 '10 15:05

Devyn


1 Answers

I've had fairly good success implementing an XMPP client in Javascript by using HTTP Bind approach to XMPP BOSH. I don't know about AMQP, but for client-side access, I love XMPP. A few words why.

ejabberd already includes BOSH support, and to use with Javascript (and presumably Flash) you just need to direct your server to redirect requests to port on which you configure ejabberd to listen for HTTP requests. (And even this only because Javascript security model in today's browsers forbids Javascript requests to different domains and even different ports.)

Since XMPP is a bunch of quite trivial small XML documents, it should be fairly easy to encode them in any language you pick.

Since it's widely supported, you might be able to avoid requiring your users to register with your service, which they will most certainly appreciate.

Implementing XMPP means you can trivially add instant messaging support to your game, with federationing to the rest of the Jabber network (including Google Talk).

Since I don't know anything about AMQP, I cannot compare them -- but I can say why I'll always first consider XMPP for my future multiplayer projects.


My personal reason for choosing ejabberd is simple -- it's super easy to install and configure on Debian. I'm almost completely unfamiliar with Erlang and Java; what I understand, however, about Erlang is that it makes scalability easy to achieve, and ejabberd people say they have achieved it.

If you want to do server side logic checking, I'm afraid I don't know of any good method. I'd go with a proxy PHP script doing sanity checking on the incoming XMPP BOSH message, then forwarding it to the server, instead of just forwarding it via Apache's mod_rewrite.

As mentioned above, you will definitely have to do proxying of some sort (with mod_rewrite or with PHP or in some other way) since the XMPP server will listen on a different port than the "main" web server, and Javascript cross-domain security model does not allow doing XMLHTTPRequest on a different port.

So, sanity checking might be easiest done while relaying BOSH requests to XMPP server of your choice. Digging into the server software might not be the best way to do this type of checks. It would take long, and would probably make it harder to integrate with the rest of your game.

Alternatively, I stumbled upon an answer that mentions XMPP components and ejabberd modules. This will be an interesting read for me, too.

Good luck, and be sure to drop a comment with the name of the game when it's done -- I'd love to see it :-)


I just noticed someone else posted a very similar question to yours. Its answers contain some more interesting info for you.


On using XMPP with Flash:

You could nevertheless use HTTP binding (BOSH) with Flash. In fact, while HTTP binding allows Javascript to access XMPP, it was conceived for a variety of applications, such as mobile connections that can often break.

I mostly figured out how to establish the connection by observing communications between web-based client JWChat and ejabberd (for info on BOSH), and then communications between cross-platform client Psi and ejabberd (for info on protocol itself). With JWChat and WebKit's Web Inspector or with Firebug for Firefox, one can easily track XMLHttpRequests being done towards the server. With Psi, one can turn on the XML console and read the communications log. Combined with prototyping a client in a language of your choice, studying BOSH and XMPP turned out to be very easy.

Also, following XEPs are useful: XEP-0124, XEP-0206.

O'Reilly book that I'm reading right now, "XMPP: The Definitive Guide" (P. Saint-Andre, Kevin Smith, Remko Tronçon; much cheaper on Apple's App Store) also gives you the feeling "why things are done the way they are", and documents many small things and various applications of XMPP.

After that, implementing a BOSH-based client could turn out to be rather easy. I have no experience with coding with Flash apart from making a button play and pause, so take this with a grain of salt :-)

like image 64
Ivan Vučica Avatar answered Sep 19 '22 23:09

Ivan Vučica