actionscript-3actionscriptairosmfakamai

Google blocking Adobe Air network check at large scale


I have an Adobe Air desktop app that was used for an event recently that thousands of people used simultaneously started getting failed network checks when using google.com as a polling URL. Having each app checking every 3 seconds to that URL, about 10 minutes into the event every app started being redirected to a validation page on Google asking the user to prove they aren't a robot which obviously they couldn't see and therefore all users were told they had no internet. I am already using Akamai's Advanced Streaming plugin (which is based on OSMF [which uses NetStream]) for the video streaming. Is there a better way to check for a network connection (preferably just using the existing NetStream object).

Here is the existing code for the network monitor:

public function checkNetwork(url:String):void {
    var urlRequest:URLRequest = new URLRequest(url);
    urlRequest.method = "GET";
    urlMonitor = new URLMonitor(urlRequest);
    urlMonitor.addEventListener(StatusEvent.STATUS,onStatusChange);
    urlMonitor.pollInterval = 3000;
    urlMonitor.start();
}

private function onStatusChange(event:StatusEvent):void {
    if(urlMonitor.available) {
        isNetworkDown = false;
        dispatchEvent(new Event("NetworkManager.NETWORK_UP"));
    }
    else {
        isNetworkDown = true;
        dispatchEvent(new Event("NetworkManager.NETWORK_DOWN"));
    }
}

Solution

  • I don't think polling a remote URL is the best way to check for internet connectivity (At least every 3 seconds). AIR has the ability to check the network itself like so:

    air.NativeApplication.nativeApplication.addEventListener(air.Event.NETWORK_CHANGE, onNetworkChange);
    
    function onNetworkChange(event)
    {
        //Check resource availability
    }
    

    The Event.NETWORK_CHANGE event does not indicate a change in all network activity, but only that a network connection has changed. AIR does not attempt to interpret the meaning of the network change.

    http://help.adobe.com/en_US/AIR/1.5/devappshtml/WS5b3ccc516d4fbf351e63e3d118666ade46-7fcc.html

    With that said, I would put your polling request inside the onNetworkChange event that way it checks only when necessary.