question

Ozan Yilmaz avatar image
Ozan Yilmaz asked

How to handle poor Internet connection?

Hello everyone,

While I was testing the game, I realized that if a client has a poor Internet connection, the result of Cloudscript sometimes doesn't reach the client. I think, it's due to the timeout value. Is there a way to handle this?

In my case, I tried to sell an item in my inventory. I pressed the sell button and waited for about 30 seconds. After that, the code executed the error callback with the error code of 1123. (The error isn't about making too many API calls too quickly. I check the Internet connection after getting the error, and the phone had a poor Internet connection). However, when I checked the inventory on PlayFab, the item was sold. So that means the request reached PlayFab, but the function result couldn't reach the client.

This causes the item still appears on the client since I couldn't get the result. My current solution is that if the client tries to sell the item again after the error, I return a result that represents "item couldn't find" message from Cloudscript and remove the item on the client side. So that the both inventories on PlayFab and the client will be synced.

I wonder if there's any other solution for this? Or in general, how can I handle a poor Internet connection?

10 |1200

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

1 Answer

·
Citrus Yan avatar image
Citrus Yan answered

One way to handle this is to have a shorter request timeout (slightly higher than the maximum “CloudScript execution time” + “http request time”) so that your program don’t need to wait too long when having a poor internet connection, and, while processing the CloudScript , set the item in “loading” status (not interactable). If the request timed out, you can then check the sync status of the inventory on PlayFab and the client and decide whether it should get removed from the client side or not.

3 comments
10 |1200

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

Ozan Yilmaz avatar image Ozan Yilmaz commented ·

That's better than my solution, but I have a question about the request timeout. Do I need to setup a shorter request timeout manually, like a timer in local to check if any result reached to the client? Or do I need to change some code in PlayFab SDK.

0 Likes 0 ·
Citrus Yan avatar image Citrus Yan Ozan Yilmaz commented ·

You can set your WebRequestType to HttpWebRequest in your PlayFabSettings and set the custom timeout:

0 Likes 0 ·
Ozan Yilmaz avatar image Ozan Yilmaz Citrus Yan commented ·

Thank you.

0 Likes 0 ·

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.