Page 1 of 1

Sending to a user after userLost

Posted: 05 Sep 2007, 08:32
by potmo
Hi!

Id like to send a "You have been disconnected due to inactivity"-message to a client.

I get the "userLost"-event in handleInternalEvent() when a user has been disconnected due to inactivity, but it doesnt seem to be possible to send a message to the user since the user already has been disconnected.

Also i think that i get the "userlost"-event when the client closes the connection as well.

1. Is there any way to know if the user was lost "due to inactivity" or "client closed connection"?

2. Is there any way to send a message to a client that have been disconnected due to inactivity? Or do i have to create my own timers and stuff?

Posted: 06 Sep 2007, 05:37
by Lapo
1. Is there any way to know if the user was lost "due to inactivity" or "client closed connection"?
no, while it's true that the server could tell you if he did close the connection forcefully, this information is not passed in the event.
There can be many other cases in which this wouldn't work and the client would be lost anyways.
2. Is there any way to send a message to a client that have been disconnected due to inactivity? Or do i have to create my own timers and stuff?
Kind of hard to send a message to a disconnected client ;) :D
Anyways, you could easily detect this on the client side. When disconnection occurs you should check the last time the user sent a message against a threshold value.

HTH

Posted: 06 Sep 2007, 07:03
by potmo
Lapo wrote: Kind of hard to send a message to a disconnected client ;) :D
HTH
yeah :D but if i want to send a message right before the user gets disconnected due to inactivity i have to set the built in threshold to infinity and build my own timer/disconnector?

Posted: 06 Sep 2007, 16:47
by cevans
All that isn't necessary. The client receives an OnConnectionLost event. This event is triggered when the connection to the server is closed either by the client or server.

So just display your disconnect message on the client when that event is triggered. :)

Posted: 07 Sep 2007, 15:14
by potmo
but i can't send a message "You lost your connection cos' you have been inactive for too long" to the client?

Posted: 08 May 2008, 08:50
by kmk
I guess the issue is, that smartfox could not distinct between "Connection is broken by network" and "Connection hangup by smartfox"

Best regards,

Michael

Posted: 08 May 2008, 09:41
by Lapo
Why don't you do it from client side?
If the server will drop you after 5 minutes of inactivity, you could simply monitor this on the client and after 4 minutes show a popup that says ... "You're going to be disconnected in 1 minute, because you haven't been active"

Posted: 08 May 2008, 13:46
by kmk
Thank you for propose, but this would require access to "MaxUserIdleTime" to give the client a clue about that idle-time.

Posted: 08 May 2008, 15:02
by Lapo
You could pass this value to the client app via a configurable external parameter. Usually the maxIdleTime on the server side does not change frequently.

If you prefer a server-side solution you could read the User.getLastMessageTime() and see how much time the user has been idle. Before the server disconnects the user you could send a warning.

You can also read the maxUserIdleTime value from server side like this:

Code: Select all

import it.gotoandplay.smartfoxserver.config
...
...

int maxIdle = ConfigData.MAX_USER_IDLETIME
hope it helps

Posted: 09 May 2008, 05:59
by kmk
I guess a server side mix of it will be the right solution for us. Nevertheless, to have a dedicated event for the idle stuff with a open channel to the client could be an improvement.

Thank you again Lapo!