views:

136

answers:

2

I want to load data from my web server, I want it be the AJAX/Comet way, my web-server long holds the request, response it until something happened. Thus, I wrote some as3 code like this:

    private function load(): void {
        var request:URLRequest = new URLRequest(url);
        var variables:URLVariables = new URLVariables();
        variables.tick = this.tick;
        request.data = variables;
        urlLoader = new URLLoader(request);
        urlLoader.addEventListener(Event.COMPLETE, onComplete);
        urlLoader.addEventListener(IOErrorEvent.IO_ERROR , onIOError);
        log.info("Loading info from {0}", request.url);
    }

It works, if the waiting time is short, but however, it failed with IOError 2032, seems the waiting time is out. Here is the problem, how can I do a long-polling with as3 and avoid the timeout error?

Thanks.

+1  A: 

I would suggest using BlazeDS for this kind of things. You can run into many issues if you want to build your own polling mechanism and you will have to write a lot of code.

Regarding your issue the Flash player is using the browser stack for communication, so your request will fail even if you have an html/js application. Check your browser documentation how to increase the timeout.

Cornel Creanga
Agreed — you definitely want to use BlazeDS for this kind of thing. It already contains a long-polling API which will likely do everything you need, with good documentation and error handling.
Dan M
A: 

you can use a URLStream as a socket (at least for reading) and send some bogus keep-alive data from the server. Let's say 0x00 marks keepalive and 0xFF marks content, followed by a 32 bit content length and the content itself.

Don't forget to flush on server side, otherwise the server might decide to keep the 1 byte in its buffer.

Also flexcomet might be of interest to you.

greetz
back2dos

back2dos