Thursday, December 27th, 2007
Django and Comet
Arena Albionu has written about Django and Comet using the Orbited Python event driven comet server.
The article walks through the hello world of Comet... a chat server. The JavaScript looks like this:
-
-
function processGetPost()
-
{
-
var myajax=ajaxpack.ajaxobj
-
var myfiletype=ajaxpack.filetype
-
if (myajax.readyState == 4)
-
{ //if request of file completed
-
if (myajax.status==200 || window.location.href.indexOf("http")==-1)
-
{ //if request was successful or running script locally
-
if (myfiletype=="txt")
-
alert(myajax.responseText)
-
else
-
alert(myajax.responseXML)
-
}
-
}
-
}
-
-
-
function connect()
-
{
-
var nick = document.getElementById('nickname').value;
-
Orbited.connect(chat_event, nick, "/chat", "0");
-
ajaxpack.getAjaxRequest("/join/" + nick + "/", "", processGetPost, "txt");
-
}
-
-
-
chat_event = function(data) {
-
var chat_box = document.getElementById('box');
-
var div = window.parent.document.createElement('div');
-
div.className = "event";
-
div.innerHTML = data;
-
chat_box.appendChild(div);
-
chat_box.scrollTop = chat_box.scrollHeight;
-
}
-
-
function send_msg() {
-
var msg = document.getElementById('chat').value;
-
var nick = document.getElementById('nickname').value;
-
ajaxpack.getAjaxRequest("/send/" + nick + "/" + msg + "/", "", processGetPost, "txt");
-
}
-












Dion, Could you replace the current Orbited link with a link to www.orbited.org
Thanks!
It’s interesting to see how the Comet stuff starts to shape up. Back in 2006, I wrote a simple Comet server for Server-Sent DOM Events using Python and Twisted.