views:

1869

answers:

3

Hello!

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.

+1  A: 

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

VonC
OK. Thank you. I know how to handle connection events on the client. So what? How does it'll help me to overcome my server-side problem? A ton of random text isn't a good answer yet.
Artem Tikhomirov
@Artem: I agree and left a comment on your answer explaining my position on this. I have updated my answer to reflect it.
VonC
Oh, I apologize - I was quite a jerk. Thank you for your answer anyways.
Artem Tikhomirov
+10  A: 

Hi, are you on Linux? If so, it's documented and here an interesting forum to follow..basically on Linux it may work a bit crazy like :)

Ric Tokyo
Hi Ric, according to the author of this question, your answer seems to be the correct one. Could you then please vote on http://stackoverflow.uservoice.com/pages/general/suggestions/115548-bug-bounty-points-incorrectly-attributed-to-my-answer ?
VonC
Hi Ric, do you have a uservoice profil or uservoice points still left ? Because voting http://stackoverflow.uservoice.com/pages/general/suggestions/115548-bug-bounty-points-incorrectly-attributed-to-my-answer would be a good idea ;)
VonC
Hi, thanks, I voted :) (first time I ever used this feature) thanks for the heads up!
Ric Tokyo
Hi Ric, since my uservoice entry has been declined (see my updated answer above), here is a +1 for your good answer. 14 other +1 will follow, one per day, in order to not mess up with your daily rep cap of 200.
VonC
Hi thanks VonC, I read it, thank you for your fair play! :)
Ric Tokyo
+2  A: 

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.

Wimmer