Skip to main content
Participant
June 2, 2011
Question

detect upload bandwidth to fms

  • June 2, 2011
  • 1 reply
  • 1659 views

Hello,

I am trying to get the "bwcheck" application to work on FMS 4 on Amazon EC2, in order to detect my upload speed to the server and provide the best quality stream for my upload speed.

The tutorial I follow is this:

http://www.derekentringer.com/blog/flash-media-server-streaming-speed-testing-part-2-detect-upload-download-and-latency-speeds-and-port-connection/

or

http://web.archive.org/web/20080308081519/http://www.peldi.com/blog/archives/2004/01/automatically_c.html

Both are almost identical. However when I compile the .fla to .swf (having changed the URL for my server and application), and after I load the server-side code, I get the following error in my server-side log:

Method not found (recData)

I understand that apparently it is not finding the method, but I tried getting it off the function in the global scope, tried attaching it to the client, etc. but nothing worked. The original code of the server-side script is:

for ( i = 0; i < 1000; i++ ) {
     data += "S->C";
}

Client.prototype.recData = function(data) 
{
     this.ping();
     var v = this.getStats();
     this.call("ack", 0, v.ping_rtt);
}

Client.prototype.echoData = function() 
{
     this.call("onEcho", 0, data);
};

Client.prototype.getBWInfo = function() 
{
     return this.getStats();
};

Client.prototype.onConnTimeout = function()
{
     clearInterval( this.connTimeout );
     this.connTimeout = null;
     application.disconnect(this);
}


application.onConnect = function(client, id)
{
     trace("connect: ");
     // Establish the connection
      application.acceptConnection(client);
}
    This topic has been closed for replies.

    1 reply

    Nikhil_Kalyan
    Participating Frequently
    June 7, 2011

    Hi,

    Thanks for trying out the FMS on cloud.

    Can you send us the full main.asc if it is fine ? I think that would be faster for us to see for any quick changes and revert back to you.

    Thank you !

    Participant
    June 11, 2011

    Dear Nikhil,

    Thank you for responding to my problem.

    Funny thing is that now it works.. I loaded a new AMI, with FMS 4.0.2, and now it just worked. I used the second link I posted:

    http://web.archive.org/web/20080308081519/http://www.peldi.com/blog/archives/2004/01/automatically_c.html

    First time I received again an error about the "data" variable:

    2011-06-11    07:24:06    1543    (e)2641173    Sending error message: /mnt/applications/bwcheck/bwcheck.asc: line 5: ReferenceError: reference to undefined property "data"    -
    2011-06-11    07:24:07    1543    (e)2641173    Sending error message: Method not found (recData).    -
    2011-06-11    07:24:07    1543    (e)2641173    Sending error message: Method not found (recData).    -


    However when I added initialisation for it above the loop, all errors disappeared, and it worked.

    ---

    Source code for server-side .asc :

    data = "";

    for ( i = 0; i < 1000; i++ ) {      data += "S->C"; } Client.prototype.recData = function(data) {      this.ping();      var v = this.getStats();      this.call("ack", 0, v.ping_rtt); } Client.prototype.echoData = function() {      this.call("onEcho", 0, data); }; Client.prototype.getBWInfo = function() {      return this.getStats(); }; Client.prototype.onConnTimeout = function() {      clearInterval( this.connTimeout );      this.connTimeout = null;      application.disconnect(this); } application.onConnect = function(client, id) {      trace("connect: ");      // Establish the connection       application.acceptConnection(client); }

    ---
    Source code for local fla/swf:

    // Once you have established a net connection to a FCS application // call "startTest" method to compute the upstream and downstream bandwidth. // How it works : // First measure bandwidth between client to server by sending data using nc.call for 5 seconds // Measure total data sent during this 5 second interval // Trigger the sever side code to start sending data from sever to client and measure total data // recived for 5 seconds. // Using the above data compute the bandwidth. // Look at bwcheck.asc on what you need to add to your server-side script. function startTest( nc ) {      _global.bwInfo = new BandwidthInfo(nc);      _global.bwInfo.start(); } ///////////// Bandwidth check methods ///////////////////////////// for ( i = 0; i < 1000; i++ ) {      data += "C->S"; } function BandwidthInfo(nc) {      this.nc = nc;      this.maxLength = 10;     // number of entries to keep in the history buffer      this.bwInHistory = new Array(this.maxLength);      this.bwInCtr = 0;      this.bwOutHistory = new Array(this.maxLength);      this.bwOutCtr = 0;      this.pingHistory = new Array(this.maxLength);      this.headIn = 0;          // add entries to the queue at head      this.headOut = 0;          // add entries to the queue at head      this.headPing = 0;      this.bBWOutStop = false;      this.bBWInStop = false;      this.onBWInTimeout = function() {           clearInterval(this.bwInfoTimeout); this.bwInfoTimeout = null; delete this.bwInfoTimeout;           this.bBWInStop = true;           if (this.bwInCtr == 0)           {                this.abort("Unable to receive data from server.");                return;           }           this.stop();      }      this.onBWOutTimeout = function() {           clearInterval(this.bwInfoTimeout); this.bwInfoTimeout = null; delete this.bwInfoTimeout;           this.bBWOutStop = true;           if (this.bwOutCtr == 0)           {                this.abort("Unable to send data to server.");                return;           }           trace( "Test bandwidth from server...");           this.bwInfoTimeout = setInterval(this, "onBWInTimeout", 5*1000);           this.serverToClient();      }      this.clientToServer = function() {           this.time = getTimer();           size = 0;           bwinfo = this;           this.nc.ack = function( pingVal ) {                if ( !bwinfo.bBWOutStop )                {                     bwinfo.bwOutHistory[bwinfo.headOut++ % bwinfo.maxLength] = Math.floor(size/(getTimer()-bwinfo.time)*1000);                     bwinfo.pingHistory[bwinfo.headPing++ % bwinfo.maxLength] =  pingVal;                     bwinfo.nc.call("recData", 0, data);                     size += 4000;                     bwinfo.bwOutCtr++;                }           }           this.nc.call("recData", 0, data);           this.nc.call("recData", 0, data);      }      this.serverToClient = function() {           this.time = getTimer();           size = 0;           bwinfo = this;           nc.onEcho = function() {                if ( !bwinfo.bBWInStop )                {                     bwinfo.bwInHistory[bwinfo.headIn++ % bwinfo.maxLength] = Math.floor(size/(getTimer()-bwinfo.time)*1000);                     this.call("echoData", 0, 0);                     size += 4000;                     bwinfo.bwInCtr++;                }           }           nc.call("echoData", 0, 0);           nc.call("echoData", 0, 0);      }      this.start = function() {           trace( "Test bandwidth to server...");           clearInterval(this.bwInfoTimeout); this.bwInfoTimeout = null; delete this.bwInfoTimeout;           this.bwInfoTimeout = setInterval(this, "onBWOutTimeout", 5*1000);           this.clientToServer();      }      this.stop = function() {           //this.nc.onStatus = null;           //this.nc.close();           this.nc = null;           var ping_rtt = 0;           var bw_out = 0;           var bw_in = 0;           for ( var i = 0; i < this.maxLength && i < this.bwOutCtr; i++ ) {                ping_rtt = Math.max(ping_rtt, this.pingHistory);           }           for ( var i = 0; i < this.maxLength && i < this.bwOutCtr; i++ ) {                bw_out += this.bwOutHistory;           }           bw_out /= Math.min(this.maxLength, this.bwOutCtr);           bw_out = Math.round((bw_out/1024) * 8);           for ( var i = 0; i < this.maxLength && i < this.bwInCtr; i++ ) {                bw_in += this.bwInHistory;           }           bw_in /= Math.min(this.maxLength, this.bwInCtr);           bw_in = Math.round((bw_in/1024) * 8);           var s;           s += "Bandwidth\n";           s += "   Upstream: " + bw_out + " Kbits/sec\n";           s += "   Downstream: " + bw_in + " Kbits/sec\n";           s += "   Latency: " + ping_rtt + " ms\n";           if (ping_rtt > 1000) {                s += "Warning: Your network appears to have a very high delay. You may experience poor synchronization in a meeting.\n\n";           }           if ( (bw_in > 500) && (bw_out > 200) ) {                s += "Your connection supports LAN speed.\n\n";           } else if ( (bw_in > 250) && (bw_out > 80) ) {                s += "Your connection supports DSL speed.\n\n";           } else if ( (bw_in > 20) && (bw_out > 15) ) {                s += "Your connection supports modem speed.\n\n";           } else {                s += "Warning: Your connection is slow. Meetings will run very slowly.\n\n";           }           trace(s);      }      this.abort = function(reason) {           trace( "Failed " + reason);      } }