| 熱愛鑽研 |
 |
Ajax ActionScript
Flash Flash Lite Flex
Flash Remoting FlashCom
Director
Lingo PHP
Multiplayer Game
|
| 搜尋 |
 |
 |
|
 |
 |
| 偵測和踢走已經斷線的使用者
|
(17-06-2004) |
 |
有時,FlashCom對於一些突然斷線的使用者,例如:當機、網絡失靈、拔掉網路電線等,onDisconnect無法觸發,因此並不知道此使用者已經走了,讓這些使用者存在,會影響FlashCom應用程序的商業邏輯上運作,因此有必要偵測和踢走已經斷線的使用者。
雖然,可以用Clients.ping偵測使用者是否仍然連線,但這方法並不是百分百有效,因為不同OS釋放一個Socket時間不同,例如Mac比Windows用較長時間,有時甚至用上一分鐘多,所以FlashCom難以很快知道使用者已經走了。
比較有效的做法,需要Server和Client相向回覆,Server向Client問候,Client有回覆,證實它仍然存在,否則將它踢走。以下是在Server main.asc的代碼:
application.onAppStart = function() {
pingClientID = setInterval(pingClient, 10000);
};
application.checkForAlive = function(client) {
var res = new Object();
res.client = client;
res.onResult = function(val) {
trace("client is ok");
};
res.onStatus = function(info) {
trace("client didn't respond");
application.disconnect(this.client);
};
var executed = client.call("areYouOk", res);
if (executed == false) {
trace("Client is dead, disconnecting");
application.disconnect(client);
}
};
function pingClient() {
for (var i = 0; i
application.checkForAlive(application.clients[i]);
}
}
在Client FLA中加入:
myConnection_nc = new NetConnection();
myConnection_nc.areYouOk = function() {return true;} |
| 本文章由luar發表。 |
不錯。不知道有沒有辦法在服務器端踢人的時候端調用client端的方法往數據庫寫入相關信息呢
你有點概念混淆,這些被踢走Client早已不存在,只是FlashCom Server需要清理垃圾。
這樣會不會給PLAYER帶來負擔?
這個時候客戶端已經離線了,那麼在flashcom上能做到對數據庫的處理嗎?比如當有人離線了,我想從數據庫里刪除信息。
在鄧那總是要求踢我呀!我刷新都沒辦法呀!他們總是說我用同樣的ip狂登:(冤枉呀
如果就可用性来说,这个办法绝对可取。可是从实时性来讲,没10秒钟扫描一次,是不是有点慢呢?
如果把扫描频率提高,那又会不会给服务器带来很大的负担的。
請問我怎麼用不得呢? 謝謝
您好:我是用Flash內建的元件,但是卻沒有用,請問
myConnection_nc = new NetConnection();
myConnection_nc.areYouOk = function() {return true;}
這個是直接加到FLA的動作內就可以了嗎?謝謝..
還有另種方法..
function pingClient() {
for (var i = 0; i<application.clients.length; i++) {
if(application.clients[i].ping(); ){
//The client is still there, nothing will be done to it
}else{
//The client isn't responding, send it a warning
application.clients[i].call("connectionOut");
//just cut off the connection
application.disconnect(applcation.clients[i]);
this.talkDataBase.data.availableUsersCount --;
}
}
}
ping不是好方法,對於某些網絡User,就算走了,都會return true,而且在FlashCom 1.5,它經常return true
| |
|
 |
 |
| 同組文章 |
 |
|