Forum Moderators: open

Message Too Old, No Replies

event driven ajax; comet; "reverse ajax"

         

distorto

5:53 pm on Mar 12, 2008 (gmt 0)

10+ Year Member



I have an ajax "listener" that I am trying to do away with. I have been reading about COMET and event-driven ajax in general (reverse ajax, html push, pushlets, etc). There;s a lot of info out there and many different frameworks. Is anyone on here doing any event driven stuff?
"pushing" data to the user after a server event trigger.
I would love recommendations on which direction to go. I have also read that to implement this responsibly, you should be using a subdomain to handle the extra connection.

httpwebwitch

8:45 pm on Mar 12, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Oh yes, lots. Only experimentally and/or in highly controlled situations, and it wasn't called "COMET"... Today is the first time I've heard that name for it! Basically the technique is to create a page that takes a really, really long time to "load" (intentionally, perhaps by starting a long or infinite loop), which will flush() content out periodically or when certain events happen in the server-side process.

I've used the technique when running very complex long-lived server processes, when I wanted a progress meter. Your server process could be a huge SQL operation, a crawler indexing pages, mashing up APIs, or just a really long loop... anything that takes a long time to complete, thus holding the HTTP connection open.
How it works is really simple. Let your server script go do what it wants. And every once in a while, you "flush()" some content.

in PHP:


print("one");
flush();
$i=100000000000000;while($i>0){$i--}; // wait a long time
print("two");
flush();
$i=100000000000000;while($i>0){$i--}; // wait a long time
print("<script>alert('hi there!')</script>");
flush();

In the server-side script, define certain events, times, or milestones at which you will flush() content to the client.

I'm very skeptical of how well this would scale. I certainly wouldn't try anything like this on a publicly-accessible website - I'm pretty sure my server would barf. Yet if developers are going to begin dusting this old technique off, optimizing machines that can handle it, and making applications that use it responsibly, I'm already intrigued.

I don't know if I can get used to calling it "COMET".

distorto

9:06 pm on Mar 12, 2008 (gmt 0)

10+ Year Member



I think Alex Russell is the guy who coined the term. He wrote a great article on the subject. Check out comet(programming) on wikipedia for a bunch of links. IBM has a great article on the subject in which they tell you "How Jetty 6 differs" from comet. Check cometd (I think it's a client) as well.
I guess event driven ajax is a better way of referring to it. I find this topic really exciting.

MarkFilipak

1:17 am on Mar 14, 2008 (gmt 0)

10+ Year Member



I find I'm writing more and more asynchronous, multithreaded javascript every day -- sort of "scrubbing bubbles". Ajax is driving some of it because: what's the point of using Ajax unless it's asynchronous, eh? Right now, javascript and Ajax is a forum -- this forum. I think that, perhaps, asynchronous javascript may deserve it's own forum. What do y'all think?