1

任何人请帮忙,我怎样才能在闪存媒体服务器上找到客户端断开连接(由于不是手动切断电源)。我的 fms 代码是下一个

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.");
}

如果客户端手动关闭应用程序,则调用onDisconnect事件处理程序,但如果由于断电或客户端禁用网络连接,则不会调用它。

请帮助我。

4

1 回答 1

0

到目前为止,我不知道当用户由于断电或禁用网络连接而断开连接时,onDisconnect事件处理程序不起作用的原因。但我找到了另一种识别它的方法。下面是接受客户端连接的代码,然后每 15 秒我检查客户端是否仍然处于活动状态(在失去网络连接后)然后断开它,我们得到“NetConnection.Connect .Closed”在客户端。

    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.");
        }
于 2013-11-08T11:55:26.103 回答