views:

413

answers:

2

I'm writing an AIR application that communicates with a server via XmlHttpRequest.

The problem that I'm having is that if the server is unreachable, my asynchronous XmlHttpRequest never seems to fail. My onreadystatechange handler detects the OPENED state, but nothing else.

Is there a way to make the XmlHttpRequest time out?

Do I have to do something silly like using setTimeout() to wait a while then abort() if the connection isn't established?

Edit: Found this, but in my testing, wrapping my xmlhttprequest.send() in a try/catch block or setting a value on xmlhttprequest.timeout (or TimeOut or timeOut) doesn't have any affect.

A: 

If the server is offline you should get a status code 401. Check for this code inside the onreadystatechanged function

EDIT: Sorry my bad. Check for 404. Usually means resource not found.

deostroll
No you won't. If it is offline you'll get nothing, 401 is an authorization failed error and requires the server be online.
stimms
A: 

Seth, did you ever figure out a solution to this problem? I'm having the same issue with an XMPP library (JSJaC) that I'm using for a desktop chat application. I receive no indication of a connection failure in AIR, but I do when I use JSJaC in a normal browser.

Daniel
Nope. I assume that it's an "upstream" problem (something with webkit), but I haven't looked into it for a while.
Seth

related questions