Back when I was a student I messed around with websockets (back then it was grizzly on glassfish). Now adays most of my development is done in python. The nice thing about websockets is that it's like a TCP-socket where both parties can send data, websockets are like this, but over HTTP. This allows the server to send data to the client without the client being the active party.
The basic "usecase" for long-polling is described below.
- The client initiates an ajax-request to the server.
- The server check to see if it has something to return, if it has, it returns it and we go back to step 1.
- If the server had nothing to return, it waits for a period of time (in my case 20 seconds), check now and again if it has something to return. If it finds something, it returns it and we go to step 1.
- If the 20 seconds pass and the server still does not have anything to send the connection is closed (ie the server returns 200 OK or similar), and the client makes a new connection from step 1.
This method brings a lot of overhead, on the plus side it is supported on all browsers that can make ajax-requests reasonably well.
A running version can at the time of writing be found here:
The source can be found here:
I will most likely try to put it up in the cloud (ie GAE, which support Django 1.4 these days), to make sure it stays up.