Air detection network

Source: Internet
Author: User
Package com.juyou.util.net {import flash. events. statusevent; import flash.net. URLRequest; import air.net. urlmonitor;/*** network listener **/public class netchecker {Private Static Var request: URLRequest = new URLRequest ("http://www.baidu.com"); Private Static Var monitor: urlmonitor; /** detection interval */Public Static Var _ interval: Number = 10000; Private Static Var available: Boolean = true; Private Static Var ob Serverlist: vector. <inetobserver> = new vector. <inetobserver> (); Public Function netchecker () {}/ *** register the observer object * @ Param OBJ observer object */public static function attach (OBJ: inetobserver ): void {If (observerlist. indexof (OBJ) =-1) {observerlist. push (OBJ) ;}}/*** Delete observer object * @ Param OBJ observer object */public static function detach (OBJ: inetobserver): void {var index: int = observerlist. indexof (OBJ); If (Index =- 1) return; observerlist. splice (index, 1);}/*** notifies all registered observer objects */Private Static function nodifyobservers (): void {for each (var obj: inetobserver in observerlist) {obj. updatenetavailable (available);}/*** start listening to network conditions **/public static function monitornetwork (): void {If (! Monitor) monitor = new urlmonitor (request); monitor. pollinterval = _ interval; monitor. addeventlistener (statusevent. status, onstatushandler); monitor. start ();}/*** set the listening network interval * @ Param Val **/public static function set interval (VAL: number ): void {If (_ interval = Val) return; _ interval = val; If (monitor & Monitor. running) {Monitor. stop (); monitor. pollinterval = _ interval; monitor. start () ;}} publi C static function get interval (): number {return _ interval;}/*** stop listening network status **/public static function stopmonitor (): void {If (Monitor) monitor. stop ();}/*** determine whether the current network is available * @ return **/public static function get networkavailable (): Boolean {return available ;} private Static function onstatushandler (E: statusevent): void {// trace ("> onstatusevent: EVT. code = "+ E); If (E. level = "status") {va R flag: Boolean = false; If (Monitor. Available &&! Available) {trace ("network connected"); available = true; flag = true;} else if (! Monitor. available & available) {available = false; trace ("No network detected"); flag = true ;}if (FLAG) {nodifyobservers ();}}}}} package {public interface inetobserver {function updatenetavailable (Ava: Boolean): void ;}}

 

Air detection network

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.