Tuesday, March 18th, 2008

pi.comet: simple comet library

Category: Comet, JavaScript, 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:

javascript

  1. var request = new pi.comet();
  2. request.environment.setUrl("push.php");
  3. request.event.push = function(RESPONSE){
  4.           alert(RESPONSE);
  5. };
  6. request.send();

And the style of client side comet depends on the type of browser:

javascript

  1. scope.comet.constructor = function(){
  2.     this.environment.setName("piComet");
  3.     this.environment.setType(scope.env.ie?3:scope.env.opera?2:1);
  4.     this.environment.setTunnel(
  5.         this.environment.getType()==3?new ActiveXObject("htmlfile"):
  6.         this.environment.getType()==2?document.createElement("event-source"):
  7.         new scope.xhr
  8.     );
  9. }

Posted by Dion Almaer at 7:43 am
6 Comments

++++-
4.3 rating from 31 votes

6 Comments »

Comments feed TrackBack URI

That’s great.
I was thinking something of similar for passpack.

Comment by Sullof — March 18, 2008

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?

Comment by csjs — March 18, 2008

Does the endless loop you show on the side stop once the connection is broken?

Comment by jaimz — March 18, 2008

i meant on the site, not the side :p

Comment by jaimz — March 18, 2008

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”

Comment by jaimz — March 18, 2008

Pi is exactly three!

Comment by Trevor — March 18, 2008

Leave a comment

You must be logged in to post a comment.