Client reconnection

Post here your questions about SFS2X. Here we discuss all server-side matters. For client API questions see the dedicated forums.

Moderators: Lapo, Bax

Post Reply
User avatar
rewb0rn
Posts: 177
Joined: 26 Jan 2009, 12:54
Location: Berlin, Germany

Client reconnection

Post by rewb0rn »

Hey,

I just found the client reconnection value in the admin tool and checked if I'd find any more info on this in the docs or the forum, but unfortunately I didnt. Is there anything to set up on the client side or do I just set a good value like 30 seconds and all the magic happens? (Which would be best of course :P)

Also if there is, could you post a link to the docs covering this topic?

Thanks,
Ruben
itsmylifesoham
Posts: 186
Joined: 16 Oct 2011, 14:33

Re: Client reconnection

Post by itsmylifesoham »

hi,

SFS2X has a feature called SRS (smartfox reconnection system) . Lets say a chess game is going on and due to some temporary network problem a player gets disconnected from the game room. then sfs server sees the value you have set for User reconnection timeframe. lets say it was 10 seconds. then the server will attempt to reconnect that player into the gameroom again for a timeperiod of 10 seconds. When it tries to do this, on server side you will get a event called

USER_RECONNECTION_TRY
The event is fired when the SRS (smart reconnection system) option is turned on and a User is trying to reconnect.

once he is connected within the timeframe the you will get a event called

USER_RECONNECTION_SUCCESS
The event is fired when the SRS (smart reconnection system) option is turned on and a User was successfully reconnected.

from here the game goes on as normal.

In brief: The User reconnection timeframe indicates the number of seconds SmartFoxServer 2X will "wait" before dispatching a USER_DISCONNECT event, thus allowing client reconnection in case of a temporary fault in connection.
User avatar
Bax
Site Admin
Posts: 4626
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Re: Client reconnection

Post by Bax »

Official informations on the HRC system (not SRS :wink: ) can be found at the bottom of this documentation page.
Paolo Bax
The SmartFoxServer Team
set_a
Posts: 16
Joined: 23 Feb 2012, 13:24

Re: Client reconnection

Post by set_a »

Hi

There is another problem after the changing in setting "User reconnection timeframe". Flash Drive can not login in the zone if you close browser or refresh F5 (I think there will be the same error if Internet is disconected)

Flash input to the server:
1. Connect to sfs server (flash after connect to sfs server call method login(user_name, pass, ZoneName))
2. USER_LOGIN
3. USER_JOIN_ZONE

I reboot flash or close the browser:
I see event USER_RECONNECTION_TRY to the server
Flash performs the same order of input to the server (described above)

Then I get an error
api.SFSApi - Login error: Another user is already logged with the same name - this from log SFS
Login Error:User ... is already logged in Zone - this from log flash

When the time is running out "User reconnection timeframe" starts event USER_DISCONNECT
What am I doing wrong?

I understand that the problem is that the user exists but why then there is no event USER_RECONNECTION_SUCCESS?

Also, to ensure that the user can not enter from two flash under one user at the same time, I added code to the event handler USER_LOGIN

String proivdedName = (String) event.getParameter(SFSEventParam.LOGIN_NAME);
User checkUser = getParentExtension().getApi().getUserByName(proivdedName);
if(checkUser != null) {
getParentExtension().getApi().disconnectUser(checkUser, ClientDisconnectionReason.KICK);
}


I tried to remove the code but the error still persists but I really need to check that the user does not use two flashes to enter the game as the same person.

Could you help me, please

Thanks
itsmylifesoham
Posts: 186
Joined: 16 Oct 2011, 14:33

Re: Client reconnection

Post by itsmylifesoham »

oh its HRC! :D will add that to my list of abbreviations , but i see the document uses SRS too :) i like it coz its symmetric.
User avatar
Bax
Site Admin
Posts: 4626
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Re: Client reconnection

Post by Bax »

set_a, this is absolutely normal. The HRC system is intended for disconnections due to network issues: the client is still running and tries to reconnect behind the scene. If you close the browser or reload the page, you are creating a new client which the server is unable to associate to an existing session which was interrupted.
Paolo Bax
The SmartFoxServer Team
set_a
Posts: 16
Joined: 23 Feb 2012, 13:24

Re: Client reconnection

Post by set_a »

Hi

I implemented the logic reconnect user after reload or crash flash.
I need your SRS mechanism to restore the user after internet problems.

User always login with the same nick name. What am I supposed to do to avoid this error?

Thanks
User avatar
Bax
Site Admin
Posts: 4626
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Re: Client reconnection

Post by Bax »

The HRC system is not meant to do what you need to do. As I said it is not intended to help in case the client crashes.
Anyway you can use the "force logout" setting on the Zone to solve the problem that a user trying to reconnect after a crash receives the " Another user is already logged with the same name" error. With that setting set to "true", the hung username will be removed and the user can login.
Of course this doesn't preserve the user status in the game, and you will need to implement your own persistence system.
Paolo Bax
The SmartFoxServer Team
igor_ivanov
Posts: 4
Joined: 17 May 2012, 11:13

Re: Client reconnection

Post by igor_ivanov »

Hi,

It is possible that situation, when new instance of flash client is created, is not related to client crash. Let's assume that network problem was happened. User sees that there is connection problem, waits for some time... And then reloads browser page. This situation is not so seldom.

Anyway, is it posiible to set session id, which AS client sends to the server during reload process after client crash/page reload , to id of previous session in order to make HRC reconnect successfull? Maybe, there is some other way to make HRC reconnect in case new instance of client flash application is created?


Thanks,
User avatar
rjgtav
Posts: 2813
Joined: 19 Apr 2009, 11:31
Location: Lisbon, Portugal

Re: Client reconnection

Post by rjgtav »

Hello.
If my memory isn't failing, when the client tries to reconnect, it also sends the sessionToken property to the server, which is the unique Session ID generated on the last successful connection. You could temporarily store this value as a cookie and use it after refreshing the page, but the problem is that the Client API doesn't let you manually set the sessionToken property, it only lets you read it, so you can't resume the connection after creating a new client.
Maybe this could be a feature request ;)
Skills: SFS Pro, SFS2X, AS2.0/AS3.0, Java, HTML5/CSS3/JS, C#
Portfolio: https://rjgtav.wordpress.com/
SFS Tutorials: http://sfs-tutor.blogspot.com/ - Discontinued. Some examples may be bugged.
igor_ivanov
Posts: 4
Joined: 17 May 2012, 11:13

Re: Client reconnection

Post by igor_ivanov »

Thank you for reply, rjgtav.
Post Reply