Question

anyone please help, how can I find on flash media server that client disconnected (due to power cut off not manually). my fms code is next

application.allowDebug = true;
application.onAppStart = function(){
    application.users_so = SharedObject.get("SO");  
}
application.onConnect = function(client,Obj){
    client.name = Obj.name;
    application.acceptConnection(client);
    application.users_so.setProperty(client.name,Obj);
    trace("one user is now connected.");
}
application.onDisconnect = function(client){
    trace(" user lost connection.");
}

IF client manually close the application then onDisconnect Event handler is called but if due to power cut off OR client disable net-connection it does not called.

please help me in this.

Was it helpful?

Solution

till now i don't know the reason why onDisconnect Event handler doesn't work when user disconnect due to power cut off OR by disabling net-connection. But i found another way to identify it.Below is the code for accepting the client conection and then after each 15 seconds I am checking if the client is still active (after loosing net-connection) then disconnect it and we get "NetConnection.Connect.Closed" on client side.

    application.allowDebug = true;
    application.onAppStart = function(){
        application.users_so = SharedObject.get("SO");  
    }
    application.onConnect = function(client,Obj){
        client.name = Obj.name;
        application.acceptConnection(client);
        application.users_so.setProperty(client.name,Obj);
        client.interval = setInterval(checkLive, 15000, client);
        trace("one user is now connected.");
    }
    function checkLive(client){
      var stats = client.getStats();
      trace('Measured timeout: ' + stats['ping_rtt']);
     if(stats){

          if(stats['ping-rtt']>10){
                     trace('client '+ client.name +'is still connected.');
            application.disconnect(client);
          }
      }


    }
        application.onDisconnect = function(client){
            clearInterval(client.interval);
            trace(" user lost connection.");
        }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top