Sending to a user after userLost
Sending to a user after userLost
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?
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
Raketspel
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.1. Is there any way to know if the user was lost "due to inactivity" or "client closed connection"?
There can be many other cases in which this wouldn't work and the client would be lost anyways.
Kind of hard to send a message to a disconnected client2. 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?
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
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:
hope it helps
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