views:

358

answers:

2

I am creating a text-based game that implements a basic model in which multiple (10+) players interact with data and one moderator watches them and sets certain environmental statistics that affect gameplay.

Recently I have begun to familiarize myself with Django. It seems to me that it would be an excellent tool for creating a game quickly, particularly because the nature of my game depends largely on sets of data (which lends itself quite well to a database).

I am wondering how to "push" changes made by the game moderator to the players (for example, the moderator can decide to display an image to all players). The game is turn-based, not real-time, but certain messages need to be pushed out in roughly real-time.

My thoughts: I could have each player's browser poll a status periodically (say, every 30 seconds) to see if there is a message from a moderator. But this forces a lag and means different players might receive it at different times. And reducing this interval to <10 seems like a bad idea for the server.

Is there a better way to inform clients of changes? Would you suggest something other than using a web framework like Django?

Thanks!

A: 

You could use long polling.

Also, if you're creating a multiplayer game, it might be much easier and more efficient to use a server that's designed for long polling and multi-user interaction instead of using a standard HTTP server and framework.

Matti Virkkunen
A: 

In addition to long polling mentioned by Matti, the HTTP server can also stream the data by basically using one really long response and never finishing the response (but continuing to push more data to the client). The client can continue to respond to data as it comes in. As you've concluded polling is probably a bad solution for any decently sized project.

Before you can get started, you're going to want to have a fairly sound understanding of HTTP and Django. This type of technology is a little more bleeding edge and can be complex at times.

There's an interesting project which is probably worth checking out: evserver. It's an HTTP server that supports asynchronous WSGI and will allow you do develop COMET-ish apps with Django. (Disclaimer: I haven't actually used evserver, but it's on my list of "cool stuff to try")

T. Stone
Is this sort of solution comparable to what Javascript-based IM solutions like gmail chat use, or is that something entirely different?
ty
There are many different ways to do the whole 'Comet' thing and I'm not sure which gmail chat uses.
T. Stone