Skip to main content
Known Participant
May 18, 2010
Question

Does 'Application.disconnect' ever really actually disconnect clients?

  • May 18, 2010
  • 2 replies
  • 2165 views

Hi all,

I have come to believe that on some or all occasions calling 'Application.disconnect' method on a client does not actually terminate the connection. Is this so?

Documentation simply says:

"Terminates a client connection to the application. When this method is called, NetConnection.onStatus() is invoked on the client with info.code set to "NetConnection.Connect.Closed". The application.onDisconnect()

handler is also invoked."

The part that worries me is "when this method is called ... is invoked on the client". Does this mean, that all that Application.disconnect call does is invoke the event on client side? Does this mean that only client can actually terminate the connection by say invoking a NetConnection.close in the event of "NetConnection.Connect.Closed" ?

I am depending on this, because our application has blocked clients, and I can see that some blocked clients do not disappear after FMS 'disconnects' them.

    This topic has been closed for replies.

    2 replies

    May 18, 2010

    I've always found application.disconnect to terminate clients reliably. I'm fairly certain it does not rely on a client side RMI, as I regularly use application.disconnect to get rid of client objects hanging around after the client terminated a connection without FMS catching it (the issue Calmchess mentioned... that's a whole other ball of wax there). In those cases there's no client to send a response.

    When you encounter these problems, is the application.onDisconnect handler being invoked?

    amnAuthor
    Known Participant
    May 18, 2010

    Can't say if the onDisconnect is invoked or not, because it does not trace anything, can't patch it right now because the service is live and I cannot test some development-patched code because I need users for that, and that in itself takes some patching here and there. In other words, I would need a couple of days to do more testing, and I wrote the post hoping someone knows for sure what's going on in such cases.

    The reason I was asking is that I saw some of the supposedly blocked (and thus supposedly disconnected) clients happily carrying on, even after I verified in the log that the service has suppesedly disconnected them. I made a separate client-service test case and to my surprise I encountered an occasion where NetConnection.Connect.Closed did NOT get invoked at client-side after the server-side disconnect call. Then, even NetConnection.close will not help, since you have no idea you've been "disconnected" in the first place.

    Also, bear in mind, that I am referring only to server-initiated disconnects.

    Adobe Employee
    May 20, 2010

    Hi,

    To disconnect a client from server side you can call application.disconnect(client) at appropriate place, then "application.onDisconnect" method should get invoked and on client side you will get "NetConnection.Connect.Closed" and again to ensure that the clients which you disconnected should not access server so you can use application.rejectConnection(client) at proper place but you need to use correct client parameter in it and then use application.onConnectReject event handler to handle it.

    Below is the code for accepting the client conection and then after interval of 15 seconds I am checking if the client is still active then disconnect it and we get "NetConnection.Connect.Closed" on client side.

    application.onConnect = function(client) {
        this.acceptConnection(client);
        trace("Client ID in onConnect : " + client.id);
        setInterval(checkLive, 15000, client);
    }

    Client.prototype.isAlive = function(c) {
    trace("Client ID in isAlive : " + this.id);
            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);
    }

    application.onDisconnect = function(client) {
    trace("Client got disconnected...");
    }

    function checkLive(client){
    trace("Client ID in checkLive : " + client.id);
    trace("checkLive called...");
    if (client.isAlive()){
      trace("Client is not alive so disconnecting...");
      application.disconnect(client);
    }
    }

    Regards,

    Amit

    calmchessplayer
    Inspiring
    May 18, 2010

    yes  you are correct onDisconnect does not always fire such as when you pull the network

    cable or intermittantly .......you need to build a system whch tells the cl

    ient to send a message on an interval to the server if this "ping" if you will is not received th

    en disconnect the client server side and onDisconnect willl b

    e called.