| Author |
|
p0miki Flashcom Newbie

Joined: 09 January 2004 Posts: 9
|
| Posted: 10 January 2004 at 13:37 | IP Logged
|
|
|
a simpe code to get around the flashcom bug of disconnecting a client if it doesn't send data over long time.
Code:
client_nc.lastCallTime = new Date().getTime();
keepAliveIntervalID = setInterval(connectionKeepAlive, 10000);
waitingForReply = false;
function connectionKeepAlive()
{
trace(new Date() + " - keep alive interval has been reached.");
//ping only if we are not still waiting for the previous keep alive message to return.
if (waitingForReply == false)
{
currentTime = new Date().getTime();
deltaTime = currentTime - client_nc.lastCallTime;
trace("currentTime = " + currentTime + ", client.lastCallTime = " + client_nc.lastCallTime + ", deltaTime = " + deltaTime + " .");
if ((deltaTime > 45000) && (client_nc.isConnected))
{
trace( "calling server keep alive.");
waitin gForReply = true;
client _nc.lastCall Time = currentTime;
client _nc.call("cl ientKeepAliv e", new handleKeepAlive());
}
else
{
trace( "no need to send ping since client made connection with the server not so long ago.");
}
}
else
{
trace(new Date() + " - still waiting for previous keep alive message to return. skipping keep alive call for now.")
}
}
function handleKeepAlive()
{
this.onResult = function(retVal)
{
waitingForReply = false;
trace("keep alive is ok. result was = " + retVal + " .");
}
this.onStatus = function(infoObj)
{
waitingForReply = false;
trace("FAILED to get keepAlive . code = " + infoObject.code + ", level = " + infoObject.level + " .");
}
}
On the server side put:
Client.prototype.clientKeepAlive = function()
{
return true;
}
|
|
|
What the script will do is, every 10 seconds check when was the last time the client connection send data to the server. if more than 45 seconds have passed without sending data than the client will call a dummy function on the server inorder have them exchange some data (aka - ping).
I would advise to update the client_nc.lastCallTime property elsewhere in your client side script whenever you call a server side function, since if you call to a server on your own, there is no reason to ping it as well over a very shot while.
Edited by stoem on 12 January 2004 at 08:56
|
| Back to Top |
|
| |
arckid Flashcom Badass


Joined: 05 January 2004 Location: India Posts: 483
|
| Posted: 10 January 2004 at 22:02 | IP Logged
|
|
|
thanks for the cute code ... :)
__________________ Ashvin Savani (arckid)
Avinashi
Flash Platform Developer
|
| Back to Top |
|
| |
Ultimate Moderator

Super Flashcommer
Joined: 05 January 2004 Location: Canada Posts: 1130
|
| Posted: 11 January 2004 at 11:03 | IP Logged
|
|
|
That's pretty long script...
Here's mine:
_global.getPingLoginSO = function (nc) {
pingSO = SharedObject.getRemote("CLIENTPINGER", nc.uri, false);
pingSO.onSync = function() {
trace("ping");
};
pingSO.connect(nc);
clearInterval(pingServer);
_global.pingServer = setInterval(pingIt, 30000);
};
_global.pingIt = function () {
if (conn_nc.isConnected == false) {
clearInterval(pingServer);
} else {
pingSO.data.loggedInDate = new Date();
}
};
I call the getPingLoginSO() function after I successfully connect up. That's it. In every file I have up.
__________________ Blog: http://www.sti-media.com
Community Site: http://www.FMSGuru.com
Game: Checkers
|
| Back to Top |
|
| |
designtaco Flashcom Newbie


Joined: 29 July 2004 Posts: 1
|
| Posted: 29 July 2004 at 01:53 | IP Logged
|
|
|
Ultimate wrote:
I call the getPingLoginSO() function after I successfully connect up. That's it. In every file I have up. |
|
|
That's a nice snippet. Since simpleConnect initiates 2 connections (when rtmp specified) then kills one, how would you see the best way would be to integrate this code into the component?
|
| Back to Top |
|
| |
Ultimate Moderator

Super Flashcommer
Joined: 05 January 2004 Location: Canada Posts: 1130
|
| Posted: 29 July 2004 at 03:37 | IP Logged
|
|
|
Sorry, I really don't have any idea at the moment becauase I never use the components. In the beginning I tried to understand how they worked and what I could do with them but gave up because it was just easier in th end to create my own.
__________________ Blog: http://www.sti-media.com
Community Site: http://www.FMSGuru.com
Game: Checkers
|
| Back to Top |
|
| |
stoem Big Kahuna

stoem == Stefan
Joined: 05 January 2004 Location: United Kingdom Posts: 1079
|
| Posted: 29 July 2004 at 07:42 | IP Logged
|
|
|
I use this on the SS:
Code:
pingClient = function (){
for (var i =0; i<application.clients.length; i++){
var stillThere = application.clients.ping();
if(stillThere == false){
application.disconnect(application.clients );
}
}
} |
|
|
I run this on a setInterval (every x seconds) via onAppStart, seems to do the job.
stoem
__________________ Flashcomguru.com
|
| Back to Top |
|
| |
xbrotherx Flashcom Newbie

Joined: 25 October 2004 Posts: 13
|
| Posted: 25 October 2004 at 05:09 | IP Logged
|
|
|
Stoem,
sorry to jump in on this conversation late, but I think the problem I am having with not being able to resume playback of video after pausing for over 5 minutes or so is related to the time-out whatchamacallit on the server.
So I tried implementing your solution but I am not sure it worked. Can you confirm that my SS script is correct below:
Code:
application.onAppStart = function(){
keepAlive = setInterval(pingClient, 10000);
}
pingClient = function (){
for (var i =0; i<application.clients.length; i++){
var stillThere = application.clients.ping();
if(stillThere == false){
application.disconnect(application.clients );
}
}
}
|
|
|
|
| Back to Top |
|
| |
stoem Big Kahuna

stoem == Stefan
Joined: 05 January 2004 Location: United Kingdom Posts: 1079
|
| Posted: 25 October 2004 at 08:45 | IP Logged
|
|
|
yeah that code looks fine but I think you should also use Ultimate's client side script, this will hold the connection open. My SS script won't do that, all that does is clean up clients that seem to be connected but in reality are long gone.
HTH
stoem
__________________ Flashcomguru.com
|
| Back to Top |
|
| |
Ultimate Moderator

Super Flashcommer
Joined: 05 January 2004 Location: Canada Posts: 1130
|
| Posted: 25 October 2004 at 08:47 | IP Logged
|
|
|
It should look like this I think:
pingClient = function (){
for (var i =0; i<application.clients.length; i++){
var stillThere = application.clients[i].ping();
if(stillThere == false){
application.discon nect(application.clients[i] );
}
}
}
Stoem forgot to turn off forum codes when posting code... on his own forum!
__________________ Blog: http://www.sti-media.com
Community Site: http://www.FMSGuru.com
Game: Checkers
|
| Back to Top |
|
| |
stoem Big Kahuna

stoem == Stefan
Joined: 05 January 2004 Location: United Kingdom Posts: 1079
|
| Posted: 25 October 2004 at 09:06 | IP Logged
|
|
|
ah cr*p
__________________ Flashcomguru.com
|
| Back to Top |
|
| |
xbrotherx Flashcom Newbie

Joined: 25 October 2004 Posts: 13
|
| Posted: 25 October 2004 at 12:26 | IP Logged
|
|
|
Wow, thanks Stoem and Ultimate!! Man if this stuff does what I hope it will do. I can actually go outside and see the sun soon!!
Thanks again.
|
| Back to Top |
|
| |
xbrotherx Flashcom Newbie

Joined: 25 October 2004 Posts: 13
|
| Posted: 26 October 2004 at 02:37 | IP Logged
|
|
|
Ultimate, if I may, I need to ask a potentially obvious question. I assume your "keep-alive" script runs in the client (the swf) and not on the server in a .asc file? Am I correct?
|
| Back to Top |
|
| |
Ultimate Moderator

Super Flashcommer
Joined: 05 January 2004 Location: Canada Posts: 1130
|
| Posted: 26 October 2004 at 02:41 | IP Logged
|
|
|
That is correct.
__________________ Blog: http://www.sti-media.com
Community Site: http://www.FMSGuru.com
Game: Checkers
|
| Back to Top |
|
| |
xbrotherx Flashcom Newbie

Joined: 25 October 2004 Posts: 13
|
| Posted: 26 October 2004 at 02:54 | IP Logged
|
|
|
Thanks again. Testing now. :)
|
| Back to Top |
|
| |
xbrotherx Flashcom Newbie

Joined: 25 October 2004 Posts: 13
|
| Posted: 26 October 2004 at 04:08 | IP Logged
|
|
|
Ultimate, your script works great!! Thanks!
|
| Back to Top |
|
| |
kevinz Flashcom Newbie


Joined: 06 May 2004 Location: Canada Posts: 10
|
| Posted: 30 October 2004 at 00:21 | IP Logged
|
|
|
Hi Ultimate and Stoem,
Something weird happened to me, pls help me and give me some ideas .
I have written a similiar code like Stoem's in main.asc , but it doesn't work. The first thing weird is the ping() function return true for a long time after i have broken the internet connection of the test client machine. It supposed to return false , right ?
So i has to change from check the result of ping() to check the ping roundtrip time of the return of client.getStats().
The second weird thing happened, When i try to disconnect the client , the application.disconnect() return true. But the 'ghost' client is still there ! I can't get rid of this ghost client.
Any ideas !
The code as following :
function pingTimer(){
for (var i=0; i< application.clients.length; i++)
{
trace("result of ping(): "+application.clients.ping());
stats = application.clients.getStats();
trace( "Ping roundtrip time: " + stats.ping_rtt);
if (stats.ping_rtt > 20000){
trace("result of disconnect(): "+application.disconnect(application.clients));
}
}
return ;
}
application.pingTimerObj=setInterval(pingTimer,15000);
Kevin
|
| Back to Top |
|
| |