2

As the title says, I've got a air.net.URLMonitor that sometimes doesn't dispatch a StatusEvent in case the specified site cannot be reached.

Let me show you my code:

_serverURL = "http://192.168.0.20:8080/"
_monitor = new URLMonitor(new URLRequest(_serverURL));
_monitor.pollInterval = 1000;
_monitor.addEventListener(StatusEvent.STATUS, serverStatusResult);
_monitor.start();

And here is my problem, when my iPad (this is a mobile AIR application btw) is in the correct network, so the one where the specified server is available, the StatusEvent is correctly dispatched. When I'm not in that network, nothing happens and I really don't know why. Shouldn't it dispatch the event anyway?

This isn't an isolated issue, when our production environment server gets updated and isn't online, the same issue appears, however when the iPad is in offline mode and cannot reach the server because of that, the StatusEvent fires.

Is there a reasonable explanation for that, and if so, how can I correctly implement this?

Should I use a standard HTTPService instead and simply listen for ResultEvent and FaultEvent?

As usual, any help would be greatly appreciated! Cheers.

4

2 回答 2

0

你的 serverStatusResult 函数中有什么?

就像是:

public function serverStatusResult(e:StatusEvent):void {

if (! monitor.available) {

//connection has dropped so do something

}

}

我还发现设置轮询间隔对 iPad CPU 使用率有非常不利的影响。

于 2012-12-07T09:44:19.543 回答
0

解决方法很简单:
StatusEvent 有一个参数叫做 code。
变量代码是一个字符串,它可以是:

  • “服务可用”
  • “暂停服务”

好的,现在让我们看一个实现:

public function serverStatusResult(e:StatusEvent):void {

switch(e.code)
{
case "Service.available":online();break;
case "Service.unavailable":offline();break;
}

}

希望能帮助到你 :)

于 2014-02-26T13:46:53.433 回答