Sending to a user after userLost

Post here your questions about Actionscript and Java server side extensions development.

Moderators: Lapo, Bax

Post Reply
potmo
Posts: 154
Joined: 02 Feb 2007, 14:28
Location: Stockholm Sweden
Contact:

Sending to a user after userLost

Post 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?
Nisse Bergman
Raketspel
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Post 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
Lapo
--
gotoAndPlay()
...addicted to flash games
potmo
Posts: 154
Joined: 02 Feb 2007, 14:28
Location: Stockholm Sweden
Contact:

Post 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?
Nisse Bergman
Raketspel
cevans
Posts: 15
Joined: 02 Jul 2007, 11:00

Post 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. :)
potmo
Posts: 154
Joined: 02 Feb 2007, 14:28
Location: Stockholm Sweden
Contact:

Post by potmo »

but i can't send a message "You lost your connection cos' you have been inactive for too long" to the client?
Nisse Bergman
Raketspel
kmk
Posts: 4
Joined: 08 May 2008, 08:36

Post 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
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Post 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"
Lapo
--
gotoAndPlay()
...addicted to flash games
kmk
Posts: 4
Joined: 08 May 2008, 08:36

Post by kmk »

Thank you for propose, but this would require access to "MaxUserIdleTime" to give the client a clue about that idle-time.
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Post 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
Lapo
--
gotoAndPlay()
...addicted to flash games
kmk
Posts: 4
Joined: 08 May 2008, 08:36

Post 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!
Post Reply