Ben avatar image
Ben asked

Guide to Elegantly Handling Network Reachability Issues?

Hi there, I was unable to locate a guide for the recommended way to handle network reachability issues on mobile devices (or really on ANY devices).

Currently using the latest Unity SDK.

Let's walk through two cases:

Case 1: Attempt to log in with no internet

  • Error: (what error would this be? It's not mentioned on this page in the documentation)
  • What event can I register to, to attempt to log in again when the network becomes available? Is this something your API supports? Recommended cross-platform solutions, if not?

Case 2: Attempt to log in with internet, but Playfab servers not responding

  • Error: what error would this be? DownstreamServiceUnavailable (1127)?
  • I assume for this one I would retry with an exponential delay back-off as explained in the above linked article?

Case 3: Attempt to call any API call without internet

  • Error: (what error would this be?)
  • Is there a callback that tells me when the player gets logged out because they lost an internet connection before I try to send an API call? Or is the proper methodology to be reactive when I get an error from the API call?

Case 4: Attempt to call any API call, but Playfab servers not responding

  • Error: (what error would this be?) DownstreamServiceUnavailable (1127)?
  • Would I need to first log the player back in before attempting this again?

A guide on required logic flow order and recommendations for what to do specifically in the case of loss of connectivity would be super useful.

1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Ben avatar image Ben commented ·

Whoops, just kidding. That should say "four cases", not two.

0 Likes 0 ·

1 Answer

brendan avatar image
brendan answered

If you have no internet connection, the error you get back and how you handle it is a function of the game engine and/or programming language you're using. The messages aren't getting to PlayFab, so there's nothing coming from our service that would help in that case. Whether it's login or another API call, you need to decide how much you want to let the player do while in an offline state (assuming your game doesn't require a connection, due to key logic being server-side, or the game being specifically multiplayer).

The "DownstreamServiceUnavailable" error is specifically saying "you're trying to make a call that has a dependency (on Steam, iTunes, Google, Twitch, Facebook, etc.) and the service in question isn't responding". We can't guarantee the availability of third-party services, so the only thing I can recommend in those cases is to check for the error and try again later. And again, it just comes down to how much you want to let the player do without that connection. Some games will opt to just let the player keep going, saving data locally so that you can update later. In that model, it's highly likely that you'll have a significant amount of cheating, so I'd only recommend it in cases where you don't have a competitive model. If you have any leaderboards, you want to avoid giving the player easy ways to cheat like that.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Ben avatar image Ben commented ·

Got it. Is there a list of what errors to expect on a per engine and language basis?

I'm using the Unity SDK and C# - What errors should I implement code logic for in all of the 4 cases I described above?

How can I detect when it is safe to attempt to connect again in the cases that my device lost internet access?

Our game is playable locally without an internet connection. The game does not contain any competitive aspects, and we're comfortable with a minimal amount of cheating. We're using Playfab to send content over the air with the CDN, as well as your news system. Any other data stored about players is minimal, and specific to a small subset of data storage features we are comfortable being less secure.

0 Likes 0 ·
brendan avatar image brendan Ben commented ·

For "no internet connection"? No, we do not provide the error details for other languages. I'd recommend checking the Unity docs for specific error codes for that case.

For when it is safe, technically, you have no way of knowing that. The player could be spelunking for the next few hours, and you wouldn't have any way to detect that. The normal procedure games use is an exponential backoff. So, retry your call after a couple of seconds. Then increase that interval to eight seconds. Then thirty. Then two minutes. Then ten. You can cap it there, though. Re-trying every couple of seconds forever will result in devouring the player's battery extremely quickly.

0 Likes 0 ·
Ben avatar image Ben brendan commented ·

Okay, but playfab would still send some type of error when the call doesn't work, right? Is that just going to be a general non-descriptive one?

0 Likes 0 ·
Show more comments
Show more comments

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.