iOS| Disconnection during app in background

Post here your questions about the Objective-C API for SFS2X

Moderators: Lapo, Bax

rafaelb149
Posts: 25
Joined: 28 Jun 2020, 08:54

iOS| Disconnection during app in background

Postby rafaelb149 » 22 Dec 2020, 08:58

Hi

My iOS clients suffer from connection loss when going to the background for a few seconds. (iOS probably kill the TCP socket?)
I wanted to ask for your suggestion on how can I overcome the iOS disconnections because my game is not tolerant of those disconnections. When the connection drop, I can't really overcome this situation, so I kind of reset the game behind the scene.

If I could somehow prevent iOS from killing the TCP socket for a 1/2 min when the user goes to the background it will be enough for me. Most of our complaints are users that went to BG for less than 10 sec.

From your experience, can I prevent it somehow? I don't have a background capability set, may it help? (https://developer.apple.com/documentation/uikit/app_and_environment/scenes/preparing_your_ui_to_run_in_the_background/about_the_background_execution_sequence)
User avatar
Lapo
Site Admin
Posts: 21946
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: iOS| Disconnection during app in background

Postby Lapo » 22 Dec 2020, 11:18

Hi,
it is possible that iOS does that, especially if the connection is idle. It also depends on the iOS version. For instance it looks like iOS 13 is pretty aggressive at killing background processes and connections, as per this article: https://www.idownloadblog.com/2019/10/3 ... anagement/

My suggestion is to try with a "keep alive" system. Something that keeps sending small requests every few seconds to keep the connection up. The LagMonitor feature in the SFS2X client API might do the trick.
The feature is used to keep track of the client-server roundtrip time, by sending a ping to the server every 4 seconds.

Under Objective-C you can do this:

Code: Select all

[sfsClient enableLagMonitor: YES];

after a successful login.

Hope it helps
Lapo
--
gotoAndPlay()
...addicted to flash games
rafaelb149
Posts: 25
Joined: 28 Jun 2020, 08:54

Re: iOS| Disconnection during app in background

Postby rafaelb149 » 22 Dec 2020, 14:05

Thanks for the quick response, I will try it!
rafaelb149
Posts: 25
Joined: 28 Jun 2020, 08:54

Re: iOS| Disconnection during app in background

Postby rafaelb149 » 28 Dec 2020, 18:53

It doesn't help. once the screen turns off the OS probably close all the sockets excepts for VOIP.
User avatar
Lapo
Site Admin
Posts: 21946
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: iOS| Disconnection during app in background

Postby Lapo » 29 Dec 2020, 14:42

Unfortunately I don't think there's much you can do about it, especially in a game. That's just how the OS manages the processes that are not active. Background Tasks can be used to run a task while the app is not in focus, but there're restrictions there too, especially when the phone goes to sleep.

Unfortunately I don't think this solution is suited for a game. The best idea would be to have a "save state" feature on the server side that can maintain the state of the game while clients are not active/in background etc... From client side you can detect the foreground/background state changes and kill the connection or create a new one, then request the previous game state and continue. (Provided your game logic supports this kind of approach).

Cheers
Lapo

--

gotoAndPlay()

...addicted to flash games

Return to “SFS2X iPhone / iPad / OSX API”

Who is online

Users browsing this forum: No registered users and 2 guests