[ActionSprit 3.0] FMS服务器带宽检测

 

 1 package {
 2 
 3     import flash.display.Sprite;
 4     import flash.net.NetConnection;
 5     import flash.events.NetStatusEvent;
 6     import flash.events.AsyncErrorEvent;
 7 
 8     /**
 9      * @author Frost.Yen
10      * @E-mail 871979853@qq.com
11      * @create 2015-7-16 上午10:02:15
12      *
13      */
14     public class BandwidthCheck extends Sprite
15     {
16         private var _nc:NetConnection;
17 
18         public function BandwidthCheck()
19         {
20             _nc = new NetConnection();
21             _nc.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
22             _nc.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler);
23             _nc.client = new Client();
24             _nc.connect("rtmp://localhost/bandwidthcheck");
25         }
26 
27         public function netStatusHandler(event:NetStatusEvent):void
28         {
29             trace(event.info.code);
30             switch (event.info.code)
31             {
32                 case "NetConnection.Connect.Success":
33                     // 调用服务器上的本地带宽检测代码。您不需要编写任何服务器端代码。
34                     _nc.call("checkBandwidth", null);
35                     break;
36             }
37         }
38         
39         public function asyncErrorHandler(event:AsyncErrorEvent):void
40         {
41             
42         }
43     }
44 }
45 
46 
47 class Client {
48     public function onBWCheck(... rest):Number {
49         return 0;
50     }
51     public function onBWDone(... rest):void {
52         var bandwidthTotal:Number;
53         if (rest.length > 0){
54             bandwidthTotal = rest[0];
55             trace("Bandwith from server to client is: " + bandwidthTotal + " Kbps");
56         }
57     }
58 }

 

posted on 2015-07-16 11:04  晏过留痕  阅读(293)  评论(0编辑  收藏  举报