Disconnection issues on iOS

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

Moderators: Lapo, Bax

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

Disconnection issues on iOS

Postby rafaelb149 » 08 Jul 2020, 09:31

Hi

I looked for iOS disconnection issues while coming back from background after a short time, and I found long threads in the forum about it, but I didn't see an answer.

My issues is that our iOS clients face frequent lost connections when go to background for a short time (less than idle time). I'm using sfx objective-c version 1.7.10 (I see that there a newer version, but it seems the fixes are not relevant for our issue).

In addition, I've enabled HRC+, so when we back from BG, onConnectionRetry is first called, and onConnectioLost. I suspect server disconnect iOS only client. BTW, same test simultaneously on Android clients works perfectly (as already reported in old topics in the forum).

Please let me know if this issue was fixed and need special handling in iOS clients

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

Re: Disconnection issues on iOS

Postby Lapo » 08 Jul 2020, 13:15

Hi,
as regards iOS vs Android behavior, it's mostly due to the OS as you can imagine which ultimately is what manages the connections and decide whether or not a connection from a background application should live or not.

Typically we recommend to keep alive the connection by sending "pings" at constant intervals. A "ping" can be just an empty Extension request. This is enough to keep a connection indefinitely unless "something else" decides to shut it down, namely the OS.
It this happens there's not much you can do other than ditching the old connection and creating a new one.

Hope it helps
Lapo
--
gotoAndPlay()
...addicted to flash games
User avatar
Lapo
Site Admin
Posts: 22006
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Disconnection issues on iOS

Postby Lapo » 08 Jul 2020, 13:18

As regards the reconnection issues, there are cases that can't be handled.
I would recommend reading these articles on the subject, to get a better understanding of what happens behind the scenes:
https://smartfoxserver.com/blog/what-re ... tworkwifi/
https://smartfoxserver.com/blog/handlin ... e-devices/

In addition, I've enabled HRC+, so when we back from BG, onConnectionRetry is first called, and onConnectioLost. I suspect server disconnect iOS only client

No the server does not disconnect anyone. If you test in a local environment you will never see the problem happen. Typically this is due to a disconnection somewhere between client and sever (e.g. any node between the two ends)

Let me know if something is unclear
Lapo

--

gotoAndPlay()

...addicted to flash games
rafaelb149
Posts: 25
Joined: 28 Jun 2020, 08:54

Re: Disconnection issues on iOS

Postby rafaelb149 » 08 Jul 2020, 13:41

Hi

Thanks for the quick response.
By saying send ping, you mean to develop a keepAlive mechanism, but I think that when my app goes to BG this mechanism will not keep work, no?

What about the the retry callback? do we have an indication that we have already connected but didn't get onServerConnectionLost yet, so. I will not report "retry connection"? it ruin my statistics.


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

Re: Disconnection issues on iOS

Postby Lapo » 08 Jul 2020, 16:59

rafaelb149 wrote:Hi

Thanks for the quick response.
By saying send ping, you mean to develop a keepAlive mechanism, but I think that when my app goes to BG this mechanism will not keep work, no?

Honestly... I don't know. It depends on the OS and its version. We tested this several years ago and it did work, and so have done some of our clients. Also it depends on how the the OS manages background apps. I am not familiar with all the fine details of Android and iOS, especially since these mechanism may change from one release to another.

I'd say the only way to know exactly is to test, and you may need to test on all supported OS versions... :? if you want to have a complete picture.

What about the the retry callback? do we have an indication that we have already connected but didn't get onServerConnectionLost yet, so. I will not report "retry connection"? it ruin my statistics.

I am not entirely sure what you mean by this.
You're already connected but didn't get the disconnection event?

The reasons for a failure during the reconnection can be many, and it's not easy to find them out. E.g.: the half-connected situations that can occur (see the article I linked for the details of this aspect).

I'll give a simple example. Client app goes in the background and looses connection. The server notices and freezes the connection for the allowed time, however the client app is now frozen and is not going to reconnect right now, thus the server side timeout will kick in.
The client app is finally brought back to the foreground, it realizes that it needs to reconnect but it's too late and it ultimately triggers a connection lost.
Lapo

--

gotoAndPlay()

...addicted to flash games
milesstone
Posts: 1
Joined: 02 May 2021, 10:00

Re: Disconnection issues on iOS

Postby milesstone » 02 May 2021, 10:25

Lapo wrote:Hi,
as regards iOS vs Android behavior, it's mostly due to the OS as you can imagine which ultimately is what manages the connections and decide whether or not a connection from a background application should live or not.

Typically we recommend to keep alive the connection by sending "pings" at constant intervals. A "ping" can be just an empty Extension request. This is enough to keep a connection indefinitely unless "something else" decides to shut it down, namely the OS.
It this happens there's not much you can do other than ditching the old connection and creating a new one.

Hope it helps

Hi Admin, if we allow app to run in the background then can this problem be solved?
Regards
Milesstone
GBWhatsApp
User avatar
Lapo
Site Admin
Posts: 22006
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Disconnection issues on iOS

Postby Lapo » 02 May 2021, 14:58

Probably, but I can't guarantee, as we've never tested this specific scenario.

Let us know your findings.
Cheers
Lapo

--

gotoAndPlay()

...addicted to flash games
rafaelb149
Posts: 25
Joined: 28 Jun 2020, 08:54

Re: Disconnection issues on iOS

Postby rafaelb149 » 02 May 2021, 15:17

Hi milesstone, How do you do that?

Return to “SFS2X iPhone / iPad / OSX API”

Who is online

Users browsing this forum: No registered users and 3 guests