views:

62

answers:

2

I'm developing a django-based MMO, and I'm wondering what would be the best way for server-client communication. The solutions I found are:

  • periodical AJAX calls
  • keeping a connection alive and sending data through it

Later edit:

This would consist in "you have a message", "user x attacked you", "your transport to x has arrived" and stuff like this. They could grow in number (something like 1/second), but for a typical user they shouldn't reach 1/minute

A: 

There's also a third technique involving "hanging" queries:

  • Client requests an updated page (or whatever)
  • Server doesn't answer right away
  • Sometime before the request times out, there's a state update in the server, and the server finally answers the client, which can then update.
  • If there really is nothing new to tell the client within the update period, then the server responds before the timeout with a "no news" message, and the client starts up another "hanging" request.

Advantages:

  • Client doesn't have to do Ajax. You could even make regular HTML pages "interactive" like this.
  • Probably not quite as much senseless polling traffic.

Disadvantages:

  • Server needs to keep more active connections open, and service them at least once per timeout period. Also,
  • depending on how well the server code supports multi-threading (does PHP provide any help there?), it may be more difficult to code than AJAX response handling.
Carl Smotricz
A: 

Not sure if it's applicable to what you're looking for, but there's a pretty good live example of lightweight server-client communication using node.js for a simple chat service:

http://chat.nodejs.org/

David