Monday, January 8, 2007

Progress Event in Flex's URLStream

The low down is that the progress event does not work like I wanted it to. In case anyone else is attempting to use it and running into problems, I feel for you.

I have a .net aspx page which stores the Response stream in the application state and just idles, so that other page activations can write to it when needed. I keep track of client ID's and all is good: I can send the right stuff to the right clients.

However, I needed to set up polling on URLStream.bytesAvailable because ProgressEvent wouldn't fire if only a few bytes had been received. I also have to send at least 300 bytes to get Response.Flush() to actually flush! Kind of annoying. I try to avoid setInterval like the plague. Another odd thing, before any bytesAvailable is shown, I have to send about 2000 bytes. Then I can detect changes within 3-400 bytes as they come in, even if separated by 10 seconds or 10 minutes.

Now I have a framework accomplishing server push where clients can interact very quickly and be aware of eachother's actions immediately.

Say a user posts a reply in a forum you're currently looking at. Well, his page activation to save his reply will trigger a server-side event listener you established on that forum, causing you to get the updated data BEFORE it's even written to the database. Your view updates the forum live as if it were some kind of chat application. No need to refresh constantly while at work and tabbing back into that forum you're interested in, just leave it up and see the replies already there when you tab back in.

This is a HUGE step forward imo. All this talk about web 2.0 and I'm excited to be part of it.. and to be doing it right; not with some polling ajax hack.

Flex rocks.

I haven't been posting a lot of my work lately because I got a talk from the boss about keeping it under wraps. So I likely won't be posting code here anymore.

2 comments:

adam said...

I have actually observed that the ProgressEvent is fired on Firefox correctly, but I observe problems with ProgressEvent firing on IE6. Is this congruent with your experience? Please email me back if you have the chance; I am aduston at the google-provided email service gmail.

Jules said...

I'm noticing a similar problem. I've also noticed that the onprogress event in IE8's new XDomainRequest object also behaves the same way. I guess this is a fundamental flaw in IE's URL stream handling routines.