package { import flash.display.Sprite;
import flash.net.NetConnection;
import flash.events.NetStatusEvent;
import flash.events.AsyncErrorEvent; /**
* @author Frost.Yen
* @E-mail 871979853@qq.com
* @create 2015-7-16 上午10:02:15
*
*/
public class BandwidthCheck extends Sprite
{
private var _nc:NetConnection; public function BandwidthCheck()
{
_nc = new NetConnection();
_nc.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
_nc.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler);
_nc.client = new Client();
_nc.connect("rtmp://localhost/bandwidthcheck");
} public function netStatusHandler(event:NetStatusEvent):void
{
trace(event.info.code);
switch (event.info.code)
{
case "NetConnection.Connect.Success":
// 调用服务器上的本地带宽检测代码。您不需要编写任何服务器端代码。
_nc.call("checkBandwidth", null);
break;
}
} public function asyncErrorHandler(event:AsyncErrorEvent):void
{ }
}
} class Client {
public function onBWCheck(... rest):Number {
return 0;
}
public function onBWDone(... rest):void {
var bandwidthTotal:Number;
if (rest.length > 0){
bandwidthTotal = rest[0];
trace("Bandwith from server to client is: " + bandwidthTotal + " Kbps");
}
}
}