Tuesday, March 18th, 2008
pi.comet: simple comet library
Azer Koçulu thinks that you can create a comet application in 3 minutes with his new library pi.comet. It provides realtime data transfers between client and server.You can use pi.comet with any server side language.
The usage is very simple indeed:
-
-
var request = new pi.comet();
-
request.environment.setUrl("push.php");
-
request.event.push = function(RESPONSE){
-
alert(RESPONSE);
-
};
-
request.send();
-
And the style of client side comet depends on the type of browser:
-
-
scope.comet.constructor = function(){
-
this.environment.setName("piComet");
-
this.environment.setType(scope.env.ie?3:scope.env.opera?2:1);
-
this.environment.setTunnel(
-
this.environment.getType()==3?new ActiveXObject("htmlfile"):
-
this.environment.getType()==2?document.createElement("event-source"):
-
new scope.xhr
-
);
-
}
-












That’s great.
I was thinking something of similar for passpack.
Grate,
The lib’s size is almost 8K and after shrinking it’s a 6K js file. the gzip one is about 3K. so it’s really cost efficient for embedding in our web2 apps.
I believe that when we can use comet in all of browsers using two xhr connections, why we need to add some other ways to implement comet, Is there any advantages?
Does the endless loop you show on the side stop once the connection is broken?
i meant on the site, not the side :p
I’d also like to note that if you use php you should set the max timeout to 0 so you don’t get this
“Fatal error: Maximum execution time of 30 seconds exceeded in ***** on line 30″
Pi is exactly three!