PDA

View Full Version : Polling with URLLoader gives sporadic ioError #2032



jmascia
July 8th, 2008, 02:06 AM
Hello,

I have a flex app that polls a php script every 1-2 seconds and returns new data. The polling is done with a URLLoader.load call;the requests are HTTP GETs. The app listens for Event.COMPLETE, handles the incoming data, waits for 1 second, then makes another URLLoader.load call.

This process works perfectly for any duration from 4 to 20 minutes. Eventually, a URLLoader.load call fails to return Event.COMPLETE. Instead it hangs for 60 to 180 seconds (depending on which local network I'm using for internet access) and finally returns an ioErrorEvent.IO_ERROR with the message "Error #2032: Stream Error. URL: <mysite.com/foo.php". The app tries to make another URLLoader.load call, but from this point onward, none of the loads return Event.COMPLETE. Also, none of these post-error HTTP GETs appear in the access.log file of my apache (2.0.55) webserver. The app will not work again until I close and reopen the browser.

I've spent several days trying to figure this out! The time until the app crashes appears to be completely random. The problem occurs in both Firefox (2.0.0.15) and IE (7.0.5730.11). I've read that sometimes 2032 errors can be related to caching, but there's no directives (in .htaccess file or httpd.conf file) that sets the Pragma or Cache-Control response header to "no-cache".

I can't tell if the problem is on client or server end. Based on the adobe language references and the forum posts I've read, this seems to be an appropriate use of URLLoader. Can someone please offer any help!!!

(In case you're wondering I want the app to respond to events in near real-time. I originally used xmlsocket to push data to app from server. However, this communication is blocked by corporate firewalls, so I need an alternative method)

Here is (cleaned up) code:


package
{
import flash.events.*;
import flash.utils.Timer;
import flash.display.Sprite;
import flash.net.*;

public class ConnectionManager extends Sprite
{
// Public vars
public var pollTimer:Timer;
public var host:String;
public var port:int;
public var loader:URLLoader;
public var req:URLRequest;

public function ConnectionManager():void
{
}

public function init(host:String, port:int):void
{
this.host = host;
this.port = port;
this.pollTimer = new Timer(1024 * 1.0, 1);
this.pollTimer.addEventListener(TimerEvent.TIMER, pollTimerHandler);
this.pollTimer.start();
}

internal function pollTimerHandler(evt:TimerEvent):void
{
loader = new URLLoader();
trace(new Date() + " Poll");
loader.dataFormat = URLLoaderDataFormat.TEXT;
loader.addEventListener(Event.COMPLETE, onComplete);
loader.addEventListener(IOErrorEvent.IO_ERROR, onIOError);
// IE will not reload php script unless you use unique variable value
req = new URLRequest("foo.php?dummy=" + String(Math.random())) ;
try {
loader.load(req);
}
catch (error:Error) {
trace(new Date() + " Unable to load URL: " + error);
}
}

internal function onComplete(evt:Event):void
{
var targetLoader:URLLoader = URLLoader(evt.target);
loader.close();
loader.removeEventListener(Event.COMPLETE, onComplete);
loader.removeEventListener(IOErrorEvent.IO_ERROR, onIOError);
trace(new Date() + " Complete: " + targetLoader.data);
this.pollTimer.reset();
this.pollTimer.start();
}

internal function onIOError(evt:IOErrorEvent):void
{
trace(new Date() + " IOError: "+evt.text);
loader.close();
loader.removeEventListener(Event.COMPLETE, onComplete);
loader.removeEventListener(IOErrorEvent.IO_ERROR, onIOError);
this.pollTimer.reset();
this.pollTimer.start();
}
}
}


I've tried many permutations of this code with slight changes, but always same error. I really need your help. Thanks in advance!!

-JM

DopplerShift
June 6th, 2009, 01:10 PM
I know this is an old thread, but I am having this same problem. Anyone have any ideas?