• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
Locked
0

AppStats using onGetAppStats() in main.asc

Guest
Apr 03, 2012 Apr 03, 2012

Copy link to clipboard

Copied

Hi,

I am trying to collect appstats using this code in main.asc.

What is wrong here?

application.onConnect = function( p_client, p_autoSenseBW )

{

     this.acceptConnection(p_client);

   

     nc_poll=new NetConnection();

     nc_poll.connect("rtmp://localhost:1111/admin","admin","a1s2d3f4");

     nc_poll.call("getAppStats",new onGetAppStats(), "vod");   

    

    function onGetAppStats()

    {

    this.onResult = function(info)

    {

      trace("POOJA 1111");

      outputBox.text = "Info for "+appName.text+ " returned:" + newline;

      trace("POOJA 2222");

      printObj(info, outputBox);

     

    }

    }

 

    function printObj(obj, destination)

    {

     trace("POOJA 3333");

     for (var prop in obj)

    {

     destination.text += "\t";

     destination.text += prop + " = " + obj[prop] + newline;

     if (typeof (obj[prop]) == "object")

     {

     trace("POOJA 4444");

      printObj(obj[prop], destination);

     }

   }

  }

   

}

thanks

Views

1.1K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Deleted User
Apr 09, 2012 Apr 09, 2012

You're still calling getAppStats on the connection without being sure the connection is established. Invoke a method outside of onConnect in response to the onStatus event.

Votes

Translate

Translate
Guest
Apr 04, 2012 Apr 04, 2012

Copy link to clipboard

Copied

1. Wait for the onStatus event from the NetConnection before invoking methods. Otherwise, you may be calling a method on a netconnection that hasn't been completed.

2. Are you defining the nc_poll variable outside of the onConnect method? If not, the scope of nc_poll is the onConnect function, so when the function returns, the nc_poll variable will have gone out of scope, and will be eligible for garbage collection.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Apr 09, 2012 Apr 09, 2012

Copy link to clipboard

Copied

Hi JayCharles,

I think onStatus event is received as seen in logs:

2012-04-09  16:39:05    16248   (s)2641173  ******RECEIVED ONSTATUS******   -

Main.asc file code is as below, Pls help.


var nc_poll;

application.onConnect = function( p_client, p_autoSenseBW )

{

  this.acceptConnection(p_client);

  nc_poll=new NetConnection();

  nc_poll.onStatus = function(info)

  {

   trace("******RECEIVED ONSTATUS******");

  }

nc_poll.connect("rtmp://localhost:1111/admin","admin","admin123");

function onGetAppStats()

  {

    this.onResult = function(info)

    {

      trace("POOJA 1111");

      outputBox.text = "Info for "+appName.text+ " returned:" + newline;

      trace("POOJA 2222");

      printObj(info, outputBox);

   }

  }

  function printObj(obj, destination)

  {

   trace("POOJA 3333");

   for (var prop in obj)

   {

    destination.text += "\t";

    destination.text += prop + " = " + obj[prop] + newline;

    if (typeof (obj[prop]) == "object")

     {

      trace("POOJA 4444");

      printObj(obj[prop], destination);

     }

   }

  }

nc_poll.call("getAppStats",new onGetAppStats(), "vod");  

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Apr 09, 2012 Apr 09, 2012

Copy link to clipboard

Copied

You're still calling getAppStats on the connection without being sure the connection is established. Invoke a method outside of onConnect in response to the onStatus event.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Apr 10, 2012 Apr 10, 2012

Copy link to clipboard

Copied

Thanks Jay, i could write the correct code!!

One query: This is giving stats when onConnect() is called from main.asc.

If i need stats at just any time, where should i call admin api from?

thanks.

var nc_poll;

application.onConnect = function( p_client, p_autoSenseBW )

{

  this.acceptConnection(p_client);

  nc_poll=new NetConnection();

  nc_poll.connect("rtmp://localhost:1111/admin","admin","admin");

  nc_poll.onStatus = function(info)

  {

    if (info.code == "NetConnection.Connect.Success" && nc_poll.isConnected)

    {

      trace("We are connected");

      nc_poll.call("getInstanceStats",new onGetInstanceStats(), "vod/_defInst_");  

   }

  }

  function onGetInstanceStats()

  {

    this.onResult = function(info)

    {

      trace("POOJA 1111");

    var dataobj=info.data;

    trace("TOTAL NUMBER OF CONNECTIONS CURRENTLY ACTIVE: " +dataobj.connected);

    trace("NUMBER OF CONNECTION ATTEMPTS ACCEPTED BY THIS APPLICATION: "+dataobj.accepted);

    trace("NUMBER OF BYTES READ BY THIS APPLICATION: " +dataobj.bytes_in);

    trace("NUMBER OF SOCKET CONNECTIONS TO THE APPLICATION SINCE THE APPLICATION WAS STARTED: " +dataobj.total_connects);

    trace("POOJA 2222");

    }

  }

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Apr 10, 2012 Apr 10, 2012

Copy link to clipboard

Copied

LATEST

Create the connection in your onAppStart method, rather than the onConnect method.

Alternately, you can create a new class to manage this, and instantiate an instance of that class in your onAppStart.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines