Disconnected while away

Post here your questions about the Unity / .Net / Mono / Windows 8 / Windows Phone 8 API for SFS2X

Moderators: Lapo, Bax

Bathory
Posts: 54
Joined: 17 Sep 2011, 21:47

Disconnected while away

Postby Bathory » 29 Apr 2019, 19:02

Hello guys,

Need help / pointers on something :)

For my game I set the user max idle time to a certain value and I also disconnect users (kickUser) at different times from server side according to the situation. Most of the time it's because I have not received requests from a user for a while after he pressed the "home" or "back" button on his phone. So far so good.

The thing is when those users come back to the game they can't do anything. They can't send new requests. They do not get the CONNECTION_LOST event which is being listened to at all times and would return them to the login screen. I tried to put code like this in a timer to no avail:

Code: Select all

if (this.sfs == null)    {
    //return to login
    ....
}
else if (this.sfs.IsConnected == false)  {
    //return to login
    ....
}


What is the proper way to handle it?

I use SFS2X v2.13.0 and the latest client API.

Thanks
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Disconnected while away

Postby Lapo » 30 Apr 2019, 07:09

Hi,
what you're describing sounds like one of those "half disconnected" situations, where the connection has been closed from one side of the communication only. This is not unusual with mobile devices and there can be different ways to handle them.

For starters I would recommend reading these articles which will clarify some of the aspects in regards to mobile-specific issues:
https://smartfoxserver.com/blog/what-re ... tworkwifi/
https://smartfoxserver.com/blog/handlin ... e-devices/

Back to your issue, I would probably try to establish a "keep-alive" signal between client and server by sending an empty Extension request every 30-40 seconds. This usually works even when apps are put in the background.

Finally, as regards how to detect the state, there is no way :(
The triggering of the CONNECTION_LOST depends entirely on the underlying TCP stack. If the OS doesn't trigger it, the SFS2X API won't trigger the related event either. The above articles should give you more info about this.

Hope it helps
Lapo
--
gotoAndPlay()
...addicted to flash games
Bathory
Posts: 54
Joined: 17 Sep 2011, 21:47

Re: Disconnected while away

Postby Bathory » 17 May 2019, 03:10

Thank you Lapo.

When dealing with network switches you close the current connection and start a new one and then send a login request right? And then from the server you have to find the game the "old" user was in and attach the new user to that game so he receives the proper events?
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Disconnected while away

Postby Lapo » 17 May 2019, 08:05

Bathory wrote:Thank you Lapo.

When dealing with network switches you close the current connection and start a new one and then send a login request right?

You mean like WiFi to 4G or viceversa? In that case, yes.
The best strategy is to intercept the network switch via OS specific API, because you can't reliably detect it via disconnections, as they may or may not trigger. At least not in a timely fashion.

And then from the server you have to find the game the "old" user was in and attach the new user to that game so he receives the proper events?

Yes, this is a bit more specific to the game type and rules. Essentially when the user comes back you will need to rebuild the state of the game for that client.
Depending on the game type this could be accomplished via Room Variables (which keep getting updated by the other player's actions) or via an Extension call that sends the game state back to the client.

Hope it helps
Lapo

--

gotoAndPlay()

...addicted to flash games
Bathory
Posts: 54
Joined: 17 Sep 2011, 21:47

Re: Disconnected while away

Postby Bathory » 17 May 2019, 12:10

In Unity it seems like you can check the Application.internetReachability value once in a while and if it has changed from NetworkReachability.ReachableViaLocalAreaNetwork to NetworkReachability.ReachableViaCarrierDataNetwork or vice-versa then you handle the reconnection.

Thanks
Jochanan
Posts: 79
Joined: 11 May 2018, 09:12

Re: Disconnected while away

Postby Jochanan » 24 May 2019, 12:50

Bathory wrote:In Unity it seems like you can check the Application.internetReachability value once in a while and if it has changed from NetworkReachability.ReachableViaLocalAreaNetwork to NetworkReachability.ReachableViaCarrierDataNetwork or vice-versa then you handle the reconnection.

Thanks


If you have a code snippet for that, would you mind to share it?
User avatar
marsoups
Posts: 167
Joined: 14 Apr 2008, 03:30

Re: Disconnected while away

Postby marsoups » 29 Aug 2019, 02:12

Very interesting, those options above look quite good.

My producer is saying that other games recognize disconnection events quite immediately. I think her test was to minimize the app, turn off wifi, and then reopen it. If it's possible to tell if there is that disconnection when the app is given focus again, we could assume we require a new connection.

I'm also intrigued because the server has a setting to assume a timeout if there is no traffic after x number of seconds (default is 30 I think), but on the clientside, we don't have an equivalent setting.

Return to “SFS2X C# API”

Who is online

Users browsing this forum: No registered users and 23 guests