all groups > macromedia flash flashcom > august 2007 >
You're in the

macromedia flash flashcom

group:

How to Handle UnGraceful Disconnect???


How to Handle UnGraceful Disconnect??? Tyger Shark
8/20/2007 9:56:29 PM
macromedia flash flashcom:
This seems to be a major issue with FCS that hasn't really been fixed or solved
by the programming community.

When you are streaming to the FCS server and the connection is lost (internet
connection lost, cable unplugged, wireless network closed, etc..) The FCS will
not close a null stream for approx 5 minutes.

It seems that FCS is set to run some sort of detection at a specific interval.

I have seen some vague answers to this question using garbage collection and
server side scripts.

The best I have seen is to run garbage collection in main.asc, but there is no
details as to code that you need to enter into main.asc to detect this with
garbage collection. Has anyone had any success with this?

Or .....is there another workaround that can be implemented?

Tyler
Re: How to Handle UnGraceful Disconnect??? JayCharles
8/21/2007 1:27:55 AM
I bet the problem isn't that the stream isn't being released, it's that the
server isn't detecting the client disconnect, so FMS thinks the user is still
there and just isn't sending any data.When this happens, do you still see the
client connection in the console?

The problem with FCS/FMS not always detecting the client disconnecting has
been around since day one. My workaround of choice is to have each client call
a server side method once a second. The method updates a property of the client
object with the current unix timestamp. Every 5 seconds, the server runs a
function that loops through the application.clients array, and compares each
client's timestamp to the current time. If the client hasn't called in to
update their timestamp in the last 5 seconds, application.disconnect is called
on the client.



Re: How to Handle UnGraceful Disconnect??? JayCharles
8/22/2007 12:00:00 AM
Here's the idea:

On the server side, we have two functions... an application function for
looping through the client timestamps, and a client function for updating the
timestamp:

application.checkTimestamps = function(){
var tdate = new Date();
var tts = Math.ceil(tdate.getTime()/1000);
for(var a=0; b<application.clients.length; a++){
if (application.clients[b].timestamp != undefined &&
application.clients[a].timestamp < tts-5){
application.disconnect(application.clients[a]);
}
}
clearInterval(application.tsInt);
application.tsInt = setInterval(application.checkTimestamps, 5000);
}
application.checkTimestamps();

Client.prototype.updateTimestamp = function(){
var cdate = new Date();
var ts = Math.ceil(cdate.getTime()/1000);
this.timestamp = ts;
return true;
}

On the client side, we just need to call the server side client function once
a second

function updateTimestamp(){
my_nc.call("updateTimestamp", null);
}
updateInt = setInterval(this, 'updateTimestamp', 1000);

Now, if any client goes 5 seconds without updating his timestamp, the server
app will close the door. Not exacly graceful, but sometime brute force is all
we have.

If you want, you can define a result handler for a callback from
updateTimestamp, but it's not needed.

Hope it helps.
Re: How to Handle UnGraceful Disconnect??? JayCharles
8/22/2007 12:00:00 AM
Here's the idea:

On the server side, we have two functions... an application function for
looping through the client timestamps, and a client function for updating the
timestamp:

application.checkTimestamps = function(){
var tdate = new Date();
var tts = Math.ceil(tdate.getTime()/1000);
for(var b=0; b<application.clients.length; b++){
if (application.clients[b].timestamp != undefined &&
application.clients[b].timestamp < tts-5){
application.disconnect(application.clients[b]);
}
}
clearInterval(application.tsInt);
application.tsInt = setInterval(application.checkTimestamps, 5000);
}
application.checkTimestamps();

Client.prototype.updateTimestamp = function(){
var cdate = new Date();
var ts = Math.ceil(cdate.getTime()/1000);
this.timestamp = ts;
return true;
}

On the client side, we just need to call the server side client function once
a second

function updateTimestamp(){
my_nc.call("updateTimestamp", null);
}
updateInt = setInterval(this, 'updateTimestamp', 1000);

Now, if any client goes 5 seconds without updating his timestamp, the server
app will close the door. Not exacly graceful, but sometime brute force is all
we have.

If you want, you can define a result handler for a callback from
updateTimestamp, but it's not needed.

Hope it helps.
Re: How to Handle UnGraceful Disconnect??? JayCharles
8/22/2007 12:00:00 AM
Here's the idea:

On the server side, we have two functions... an application function for
looping through the client timestamps, and a client function for updating the
timestamp:

application.checkTimestamps = function(){
var tdate = new Date();
var tts = Math.ceil(tdate.getTime()/1000);
for(var a=0; a<application.clients.length; a++){
if (application.clients[a].timestamp != undefined &&
application.clients[a].timestamp < tts-5){
application.disconnect(application.clients[a]);
}
}
clearInterval(application.tsInt);
application.tsInt = setInterval(application.checkTimestamps, 5000);
}
application.checkTimestamps();

Client.prototype.updateTimestamp = function(){
var cdate = new Date();
var ts = Math.ceil(cdate.getTime()/1000);
this.timestamp = ts;
return true;
}

On the client side, we just need to call the server side client function once
a second

function updateTimestamp(){
my_nc.call("updateTimestamp", null);
}
updateInt = setInterval(this, 'updateTimestamp', 1000);

Now, if any client goes 5 seconds without updating his timestamp, the server
app will close the door. Not exacly graceful, but sometime brute force is all
we have.

If you want, you can define a result handler for a callback from
updateTimestamp, but it's not needed.

Hope it helps.
Re: How to Handle UnGraceful Disconnect??? JayCharles
8/22/2007 12:00:00 AM
AddThis Social Bookmark Button