I've run into strange problem in my Flex/Flashcom application. If client application unexpectedly disconnects from server latter does not call application.onDisconnect handler function. In witch direction should I look? Thank you.
Update I'm not using server components, but I do host this thing on Linux.
As mentioned by Artem Tikhomirov (the author of the question) in his own answer, my answer is not helpful (I keep there below as wiki, for archive).
The real answer has been given by Ric Tokyo regarding a bug on Linux, and is documented in this thread.
The only reason my answer is "chosen" is because Artem did not choose any other answer (or an answer of his own) before the 7 day limits, giving me (the first and most upvoted answer) half of the bounty points (75 over 150) automatically as explained in this SO blog entry.
First lead:
If the client is a component-base application, it needs to [handle connection events properly][9].
When you develop applications, be aware that using components introduces explicit onConnectAccept
and onConnectReject
events.
You need to include code to handle these events.
When you use components, you must modify the application.onConnect
statement in your server-side code to include the application.onConnectAccept
and application.onConnectReject
event handlers.
The last line (in order of execution) of your onConnect
handler should be either application.acceptConnection()
or application.rejectConnection()
.
If your application requires additional code following the explicit acceptConnection()
or rejectConnection()
methods, such as a message indicating that the user has been granted or denied permission to the application, you should place that code in the application.onConnectAccept
or application.onConnectReject
statements.
TIP: If you're not using media components, you cannot use application.onConnectAccept
and application.onConnectReject
.
Then, you may want to check any error message in the Flash output panel, like:
Error #2044: NetStatusEvent non pris en charge : level=error, code=NetStream.Play.Failed
at MethodInfo-1()
Error #2044: NetStatusEvent non pris en charge : level=error, code=NetStream.Record.NoAccess
at MethodInfo-1()
That would indicate a server exception non-taken into account by the client, forcing an unexpected exit.
If the client read a stream from the server, it must make sure:
- the NetConnection has succeeded
- the NetStreams (in and out) listen to NET_STATUS
A good code would like this:
var status:Function = function( e:NetStatusEvent ):void
{
trace( "status : " + e.info.code ) ;
if ( e.info.code == "NetConnection.Connect.Success" )
{
streamOut = new NetStream( nc ) ;
streamOut.addEventListener( NetStatusEvent.NET_STATUS , status ) ;
streamIn = new NetStream( nc ) ;
streamIn.addEventListener( NetStatusEvent.NET_STATUS , status ) ;
streamOut.attachCamera( cam ) ;
video.attachNetStream( streamIn ) ;
streamOut.publish( "private" ) ;
streamIn.play( "private" ) ;
}
}
Since the new versions of FlashPlayer do propagate those kind of exception, they must be monitored and then catch in the client application
If so, it's documented and here an interesting forum to follow..basically on Linux it may work a bit crazy like :)
It's possible that a client is disconnected before the (Flash Media-) server 'knows' about this. So no 'onDisconnect' function gets invoked (it never gets called by the client) until very, very late.
If you want to detect (and act upon) "lingering" disconnects early, use the client.getStats() method.
I have this server-side actionscript example:
// add method to standard class
Client.prototype.isAlive = function() {
var stats = this.getStats();
var timeout_value = 3 * 1000; // in ms.
//trace('Measured timeout: ' + stats['ping_rtt']);
if (stats)
return (stats['ping_rtt'] < timeout_value);
}
// use this in an interval which traverses the application.clients list
if (! client.isAlive())
application.disconnect(client);
You can trigger and test this 'missing onDisconnect' behavior by removing the network cable from the connected Flash client.