Thursday, December 27th, 2007
Django and Comet
<p>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 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");
-
}
-
Related Content:











Dion, Could you replace the current Orbited link with a link to http://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.
I just wrote up a basic intro to using Django with Orbited:
http://darkporter.com/?p=7