This content has been marked as final. Show 7 replies
Try to connect to the resource of interest an see what/if any response you get.
Hm. This is an application that is going to be known to live an occasionally connected environment. It will be very common to start the app in online or offline environment. There are tons of services it would want to connect to online, and the behavior of the application is significantly altered if it is not online. I'm really looking for a general "internet enabled" status. Is that not possible?
Sorry, guess I should have added this. I create a php file that only echos "ok", then make a request to this file, if the file loads then I know they are online. Then, you can monitor the status by listening for the networkChange event. So, if they are online already, and you receive such event, you'll know they went offline, and vice-verse.
The only reliable way to tell if you have an Internet connection is to try it. (If Adobe provided an Internet status API, it would have to do the same thing anyway). If you have your own public server, then a lightweight "ping" function such as that used by dzedward is a good technique.
The netChange event won't really tell you whether the user has gone on or off line. It could be a change from one network to another (such as when a user logs into a VPN). The netChange event is an excellent time to check the internet connection again, though. AIR provide some framework classes for this in the air.net package:
(Note that the air.net package isn't built in, you must add the library to your project. How you do that depends on your development tools.)
I missed the air.net package, this looks interesting.
So, if I understand, URLMonitor will poll a designated "ping" url and assign availability based on a good status code response?
I'm using Flash and I see the ServiceMonitorShim component, cool.
"The netChange event is an excellent time to check the internet connection again, though. AIR provide some framework classes for this in the air.net package"
I'm using the URLMonitor, but I can't figure out how to make it do a check when netChange happens. I have it set to poll over 5 minutes, but when I try to call myURLMonitor.checkStatus(), it tells me that checkStatus is not accessible. How do I do this?