Your AIR application can run in environments with uncertain
and changing network connectivity. To help an application manage
connections to online resources, Adobe AIR sends a network change
event whenever a network connection becomes available or unavailable.
The application’s NativeApplication object dispatches the network
change event. To react to this event, add a listener:
air.NativeApplication.nativeApplication.addEventListener(air.Event.NETWORK_CHANGE, onNetworkChange);
And define an event handler function:
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. A networked computer may have many real and virtual
connections, so losing a connection does not necessarily mean losing
a resource. On the other hand, new connections do not guarantee
improved resource availability, either. Sometimes a new connection can
even block access to resources previously available (for example,
when connecting to a VPN).
In general, the only way for an application to determine whether
it can connect to a remote resource is to try it. To this end, the
service monitoring frameworks in the air.net package provide AIR
applications with an event-based means of responding to changes
in network connectivity to a specified host.
Note: The service monitoring framework detects whether
a server responds acceptably to a request. This does not guarantee
full connectivity. Scalable web services often use caching and load-balancing
appliances to redirect traffic to a cluster of web servers. In this
situation, service providers only provide a partial diagnosis of
network connectivity.