views:

445

answers:

3

Hi all,

I'd like to know whether it's possible to easily detect (on the server side) when Flex clients disconnect from a BlazeDS destination please? My scenario is simply that I'd like to try and use this to figure out how long each of my clients are connected for each session. I need to be able to differentiate between clients as well (ie so not just counting the number of currently connected clients which I see in ds-console).

Whilst I could program in a "I'm now logging out" process in my clients, I don't know whether this will fire if the client simply navigates away to another web page rather than going though said logout process.

Can anyone suggest if there's an easy way to do this type of monitoring on the server side please.

Many thanks, Alex

A: 

I would assume BlazeDS would provide a callback or event for when a client disconnects, but I haven't worked with Blaze so that would just be a guess. First step would be to check the documentation to see if it does though, as that would be your best bet.

What I've done in cases where there isn't a disconnect event (or it's not reliable) is to add a keepalive message. For instance, the client would be configured to send a keepalive message every 30 seconds, and if the server goes more than, say, 2 minutes without seeing a keepalive then it assumes the client has disconnected. This would let you differentiate between different clients, and you can play around with the rate and check times to get something you're happy with.

Herms
A: 

The only way to do it right is to implement the heartbeat mechanism in a way or another. You can use the keep-alive from http coupled with session expire as suggested before but my opinion is to use the messaging mechanism from BlazeDS (send a message at X seconds). You can control the time interval and other aspects (maybe you want to detect if the client is not doing anything for several hours and to invalidate the session even if your client is still connected).

If you want to be notified instantly (chat application) when a client is disconnecting a solution is to have a socket (RTMP) or some emulation (http streaming) which will detect instantly if the client is disconnected, however this disconnection can be temporary (maybe the network was down for one second, and after that is ok, and you should also detect that).

Cornel Creanga
Thanks to you both Herms and Cornel. Some sort of heartbeat was what I was thinking I might have to do (and I think it should be easy to have a 'heartbeat' destination for connected clients). I was just thinking there *might* be something built into BlazeDS for this (I've not found it yet though). I'll plan for a heartbeat.Tks again
Alex Curtis
+1  A: 

Implement you own adapter extending "extends ServiceAdapter"

Then set the function:

@Override public boolean handlesSubscriptions() { return true; } So you can handle subscription and unsubscription

Then you can manage those in the manage function:

@Override public Object manage(CommandMessage commandMessage) {

switch (commandMessage.getOperation()) { case CommandMessage.SUBSCRIBE_OPERATION: break; case CommandMessage.UNSUBSCRIBE_OPERATION: break; }

}

You can also catch different commands.

Hope this help