Applications written for Adobe AIR can easily include funcitonality that detects if a connection is broken and later restored. Possible uses for this include alerting the user, locally saving data and later synchronizing, attempting to reach a backup server, etc. As you would expect, the capability is event driven making it easy to toggle functionality based on connectivity status.
This sample and many more are available with source code in Tour de Flex. An install badge is below.
<?xml version="1.0" encoding="utf-8"?>
<mx:Module xmlns:mx="http://www.adobe.com/2006/mxml" backgroundColor="#323232" layout="vertical"
creationComplete="init()" verticalAlign="middle" horizontalAlign="center">
<mx:Script>
<![CDATA[
import air.net.URLMonitor;
import flash.net.URLRequest;
import flash.events.StatusEvent;
private var monitor:URLMonitor;
private function startMonitor():void
{
monitor = new URLMonitor(new URLRequest(hostField.text));
monitor.addEventListener(StatusEvent.STATUS, checkStatus);
monitor.pollInterval = 500; // Every 1/2 second
monitor.start();
}
private function checkStatus(e:StatusEvent):void {
if(monitor.available) {
connectFlag.text = "Current Status=ONLINE";
} else {
connectFlag.text = "Current Status=OFFLINE";
}
}
]]>
</mx:Script>
<mx:HBox width="100%" verticalAlign="middle" horizontalAlign="center">
<mx:Label text="Host name or IP address:" color="white"/>
<mx:TextInput id="hostField" text="http://www.adobe.com" width="220" />
<mx:Button id="monButton" label="Start" click="startMonitor()"/>
</mx:HBox>
<mx:Label id="connectFlag" color="white"/>
</mx:Module>
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" backgroundColor="#323232" layout="vertical"
creationComplete="init()" verticalAlign="middle" horizontalAlign="center">
<mx:Script>
<![CDATA[
import air.net.SocketMonitor;
import flash.net.URLRequest;
import flash.events.StatusEvent;
private var monitor:SocketMonitor;
private function startMonitor():void
{
monitor = new SocketMonitor(hostField.text, int(hostPort.text));
monitor.addEventListener(StatusEvent.STATUS, checkStatus);
monitor.pollInterval = 500; // Every 1/2 second
updateStatus(); // Report the current status
monitor.start(); // Monitor for changes in status
}
private function checkStatus(e:StatusEvent):void {
updateStatus();
}
private function updateStatus():void {
if(monitor.available) {
connectFlag.text = "Current Status=ONLINE";
} else {
connectFlag.text = "Current Status=OFFLINE";
}
}
]]>
</mx:Script>
<mx:HBox width="100%" verticalAlign="middle" horizontalAlign="center">
<mx:Label text="Host name or IP address:" color="white"/>
<mx:TextInput id="hostField" width="180" text="www.adobe.com" />
<mx:Label text="Port:" color="white"/>
<mx:TextInput id="hostPort" width="50" text="80"/>
<mx:Button id="monButton" label="Start" click="startMonitor()"/>
</mx:HBox>
<mx:Label id="connectFlag" color="white"/>
</mx:WindowedApplication>