任何人请帮忙,我如何在闪存介质服务器上找到客户端断开连接(由于电源不能手动切断)。我的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 会调用事件处理程序,但如果由于断电或客户端禁用网络连接,则不会调用它。
请帮助我。
答案 0 :(得分:0)
到目前为止我还不知道为什么 onDisconnect 当用户因断电或断开网络连接而断开连接时,事件处理程序无效。但是我发现了另一种识别它的方法。下面是接受客户端连接的代码,然后在每15秒后我检查客户端是否仍处于活动状态(在断开网络连接后)然后断开连接,我们得到“NetConnection.Connect”关闭“在客户端。
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.");
}