Hi Richard/Charlie, based on yours and Roger’s code, I attempted to write a small flex app to detect upload BW check code and i run into an error. When I ask the debugger to continue, it seems to run and provide the result. However, I would very much like to solve the error. Do you have an idea as to why this might be happening? The code is below…
The error I get is :
SWF] Users:admin:Documents:Flex Builder 3:flexTestApps:bin-debug:FlexUploadBWCheck.swf - 633,710 bytes after decompression
ArgumentError: Error #1063: Argument count mismatch on FlexUploadBWCheck/onBWDone(). Expected 4, got 0.
asyncErrorEvtHanlder: [AsyncErrorEvent type=“asyncError” bubbles=false cancelable=false eventPhase=2 text=“Error #2095: flash.net.NetConnection was unable to invoke callback onBWDone.” error=ArgumentError: Error #1063: Argument count mismatch on FlexUploadBWCheck/onBWDone(). Expected 4, got 0.]
testing CtoS performance…
Thanks, Ramesh
------------------ code ------
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" applicationComplete="init()">
<mx:Script>
<![CDATA[
import flash.net.NetConnection;
import flash.net.NetStream;
import mx.managers.SystemManager;
private var nc:NetConnection;
private var thumb:NetStream;
private var connectionObj:Object;
private var res:Object;
private var payload:Array = new Array();
private function init():void {
res = new Object();
res.latency = 0;
res.cumLatency = 1;
res.bwTime = 0;
res.count = 0;
res.sent = 0;
res.kbitUp = 0;
res.deltaUp = 0;
res.deltaTime = 0;
//res.client = p_client;
//var stats = p_client.getStats();
res.pakSent = new Array();
res.pakRecv = new Array();
res.beginningValues = {};
for (var i:int=0; i<1200; i++){
payload[i] = Math.random(); //16K approx
}
samplePlay();
}
private function samplePlay():void{
nc=new NetConnection() ;
nc.client = this;
nc.addEventListener (NetStatusEvent.NET_STATUS,checkConnect);
nc.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorEvtHandler);
var rtmpNow:String = "rtmp://localhost/bwcheck";
nc.connect (rtmpNow);
}
private function checkConnect(e:NetStatusEvent):void{
if(e.info.code == "NetConnection.Connect.Success"){
doClientBWCheck();
}
}
private function doClientBWCheck():void {
nc.call("onClientBWCheck", new Responder(getBWCheckData, noBWData), null);
trace("testing CtoS performance...");
}
public function getBWCheckData(p_res:Object):void {
trace ("ClientBWResult: ");
var now:Number = (new Date()).getTime()/1;
if(res.sent == 0) {
res.beginningValues = p_res;
res.beginningValues.time = now;
res.pakSent[res.sent++] = now;
nc.call("onClientBWCheck", new Responder(getBWCheckData, noBWData), now);
} else {
res.pakRecv[res.count] = now;
trace( "Packet interval = " + (res.pakRecv[res.count] - res.pakSent[res.count])*1 );
res.count++;
var timePassed:Number = (now - res.beginningValues.time);
if (res.count == 1) {
res.latency = Math.min(timePassed, 800);
res.latency = Math.max(res.latency, 10);
res.overhead = p_res.cOutBytes - res.beginningValues.cOutBytes;
trace("overhead: "+res.overhead);
res.pakSent[res.sent++] = now;
nc.call("onClientBWCheck", new Responder(getBWCheckData, noBWData), now, payload);
}
trace("count: "+res.count+ " sent: "+res.sent+" timePassed: "+timePassed+" latency: "+res.latency);
// If we have a hi-speed network with low latency send more to determine
// better bandwidth numbers, send no more than 6 packets
if ( (res.count >= 1) && (timePassed<1000))
{
res.pakSent[res.sent++] = now;
res.cumLatency++;
nc.call("onClientBWCheck", new Responder(getBWCheckData, noBWData), now, payload);
} else if ( res.sent == res.count ) {
// See if we need to normalize latency
if ( res.latency >= 100 )
{ // make sure we detect sattelite and modem correctly
if ( res.pakRecv[1] - res.pakRecv[0] > 1000 )
{
res.latency = 100;
}
}
payload = null;
System.gc();
//delete payload;
// Got back responses for all the packets compute the bandwidth.
var stats:Object = p_res;
var deltaUp:Number = (stats.cOutBytes - res.beginningValues.cOutBytes)*8/1000;
var deltaTime:Number = ((now - res.beginningValues.time) - (res.latency * res.cumLatency) )/1000;
if ( deltaTime <= 0 )
deltaTime = (now - res.beginningValues.time)/1000;
var kbitUp:Number = Math.round(deltaUp/deltaTime);
trace("getBWCheckData: kbitUp = " + kbitUp + ", deltaUp= " + deltaUp + ", deltaTime = " + deltaTime + ", latency = " + res.latency + " KBytes " + (stats.cOutBytes - res.beginningValues.cOutBytes)/1024) ;
}
}
}
public function onBWDone(kbitDown:Number, deltaDown:Number, deltaTime:Number, latency:Number):void
{
trace("onBWDone: kbitDown:"+kbitDown+" deltaDown:"+deltaDown+" deltaTime:"+deltaTime+" latency:"+latency);
// app logic based on the bandwidth detected follows here
var detected_bw:Number = kbitDown;
// close the Netconnection to bwcheck
}
private function noBWData(result:Object):void{
trace("No BandWidth data: ", result);
}
public function asyncErrorEvtHandler(result:Object):void {
trace("asyncErrorEvtHanlder: ", result);
}
private function onMetaData(o:Object):void{ }
private function onPlayStatus(o:Object):void{}
]]>
</mx:Script>
</mx:Application>