Roger,
I didn’t have to change much to get your actionscript to work correctly. Adobe has done away with the onResponse callback on its own, it now has to become a Responder object with a specific callback, onResponse or onFault or both.
This following actionscript file can be used as is and works great. I have a reference to the Object res, but the responder calls itself, and references the res Object from within its code.
To anyone else who had issues getting the actionscript part of this to work, I hope this saves some headache.
Roger thanks for the Java class and for the logic to get this to work.
Cheers,
Scott Haines
var nc:NetConnection;
var res;
var payload;
var ro;
function doClientBWCheck() {
trace(“testing CtoS performance…”);
nc.call(“onClientBWCheck”, ro, null);
}
function netConnectionStatusHandler(e:NetStatusEvent):void
{
if (e.info.code == “NetConnection.Connect.Success”) {
doClientBWCheck();
}
}
function ncOnBWDone()
{
trace(“BW Done”);
}
function ncOnBWCheck()
{
trace(“BW Check”);
}
function onClientResponse()
{
trace(“got info”);
}
var totalCount = 10;
function onResult(arg){
trace(“Got some Args Bytes Out”+arg[“cOutBytes”]+" Bytes In: “+arg[“cInBytes”]+” Time: "+arg[“time”]);
var now = (new Date()).getTime()/1;
if(res.sent == 0)
{
res.beginningValues = arg;
res.beginningValues.time = now;
res.pakSent[res.sent++] = now;
nc.call(“onClientBWCheck”, ro, now);
}
else
{
res.pakRecv[res.count] = now;
trace( "Packet interval = " + (res.pakRecv[res.count] - res.pakSent[res.count])*1 );
res.count++;
var timePassed = ( now - res.beginningValues.time );
if (res.count == 1)
{
res.latency = Math.min(timePassed, 800);
res.latency = Math.max(res.latency, 10);
res.overhead = arg.cOutBytes - res.beginningValues.cOutBytes;
trace("overhead: "+res.overhead);
res.pakSent[res.sent++] = now;
nc.call(“onClientBWCheck”, ro, 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”, ro, now, payload);
}
else if (res.sent == res.count)
{
// See if we need to normalize latency
if ( this.latency >= 100 )
{
if ( res.pakRecv[1] - res.pakRecv[0] > 1000 )
{
res.latency = 100;
}
}
payload.length = 0;
// Got back responses for all packets, compute bandwidth upspeed
var stats = arg;
var deltaUp = (stats.cOutBytes - res.beginningValues.cOutBytes)*8/1000;
var deltaTime = ((now - res.beginningValues.time) - (res.latency * res.cumLatency) )/1000;
if ( deltaTime <= 0 )
deltaTime = ( now - res.beginningValues.time) / 1000;
var kbitUp = Math.round(deltaUp/deltaTime);
trace("onBWDone: kbitUp = " + kbitUp + ", deltaUp= "+ deltaUp + " , deltaTime = " + deltaTime + ", latency = " + res.latency + " KBytes " + (stats.cOutBytes - res.beginningValues.cOutBytes)/1024) ;
}
}
};
function init()
{
nc = new NetConnection();
nc.addEventListener(NetStatusEvent.NET_STATUS,netConnectionStatusHandler);
ro = new Responder(onResult);
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 = {};
nc.objectEncoding = ObjectEncoding.AMF0;
var ncClientObj:Object = new Object();
nc.client = ncClientObj;
ncClientObj.onBWDone = ncOnBWDone;
ncClientObj.onBWCheck = ncOnBWCheck;
payload = new Array();
for (var i=0; i<1200; i++){
payload = Math.random(); //16K approx
}
nc.connect(“rtmp://localhost/bwcheck”);
}
init();
-----------------------------------------------------------------------------