Creating Comet Applications In 3 Minutes Date: March 16, 2008  Tags: comet , javascript , pi    Comments(10)

First version of my pi library has been released.This version contains a comet class and you can make comet requests in your applications by using it.

Tutorial: Getting unix time from server(Sample File, Source)

Firstly, create an html file and import pi.js: <script type="text/javascript" src="pi.js"></script>

Then, send a request to push.php to get unix time from server: var request = new pi.comet(); request.environment.setUrl("push.php"); request.event.push = function(RESPONSE){ document.title = "UNIX TIME AT SERVER: "+RESPONSE; }; request.send();

Finally, create an infinite loop at push.php, import pi.pushData function to this file and print the data which will be updated each time; require_once "pi.pushData.php"; $type = $_GET["cometType"]; $name = $_GET["cometName"]; while(true){ pushData(time(),$type,$name); ob_flush(); flush(); sleep(1); }

That's all! You can get more information at pi.comet's wiki page.   


Comments:

Azer — July 2, 2008

Hi Steffen,

It will be fixed on new version.

Steffen — July 1, 2008

Hi,

This is really great. However, I am facing two issues:

1. The push function is always called twice when data is sent, even though the server sends the data only once.

2. This is not working in IE for me - however, I need to look into this more, so don't worry about it for now.

Does anyone have an idea why the push function is called twice?

Thanks,

Steffen

!phil — April 3, 2008

Azer
Thanks for sharing your code. People like you make the world go round :D

Cheers,
Phil

Azer — March 21, 2008

Hi Sentry, I will add .Net and Rails as soon as possible.For now, you can check Python example that is different from the PHP example.Thanks..

sentry — March 20, 2008

How would one implement the infinite loop in .NET or Rails. I think that .NET would crash if I try and make an infinite loop.

tarkus — March 19, 2008

cool!!!thank u for bringing them all to us!great work!thx!

azer — March 19, 2008

@rk, it works in ie7 and ie6.

rk — March 19, 2008

Do you know why it does not work in IE7?

Francesco Sullo — March 18, 2008

Hello Azer,
That's great.
I was thinking something of similar for Passpack. I think I will use your library (after my tests :)
Thanks,
F

Guillaume Theoret — March 18, 2008

Wow this is amazing, well done.

Have you checked out what kind of scalability you can get? It seems to me it might be worth plugging your front end code to an event-based backend so that you aren't busy-waiting on the server.

Leave Comment

Name:
E-Mail: (Will be not published)
Website:
 Your comment will be published after confirmation.

BROWSE BY TAGS

 appengine (1)  cherrypy (3)  comet (6)  debugging (1)  django (3)  greasemonkey (1)  javascript (11)  linux (3)  misc (9)  pi (5)  python (3)  security (1)  turbogears (2)  turkce (1)

ARCHIVES

July 2008
May 2008
April 2008
March 2008

RECENT WORK

YAMLWriter
pi.debugger
gmCeviri
pi.comet
ileri seviye javascript
View All

FLICKR

View All

LINKS

Cloudo&Hakan Bilgin
Muhammed Daud
Serdar Meydanci
Ferruh Mavituna
CherryPy
Christian Wyglendowski
the spanner
john resig
eric's weblog
dustin diaz

A Django site.