[Worked Out] network.request: how can we detect if connectivity is strong or weak

When the network connectivity is shaky (such as at busy airport using free WiFi service, for example), my app appears to stall at key juncture on my test devices (iPod Touches). I believe it stalls when the app is trying to perform some network requests (such as posting high score or achievements to Game Center or sending/retrieving data to/from the backend server.) In my app, these network requests are supposed to happen silently behind the scene and are not meant to affect the user experience. When the app detects no connection, it is currently set up to skip these network requests. So I think the solution to this problem is to check to see if the network connectivity is strong, and if it’s not, just skip these network requests as if there’s no connection (and where appropriate or necessary, notify the user that the request cannot be processed due to the network connectivity issue.)

But I’m not sure how I may go about doing this. I looked at network reachability API (http://docs.coronalabs.com/api/event/networkStatus/index.html) I also looked at the sample code ( CoronaSDK/SampleCode/Networking/Reachability ) But it doesn’t look like it returns/checks how strong the connectivity is – instead, it only returns what type of connection it has (i.e., no connection, WiFi connection or Cellular connection.) Please note, I haven’t used this API to check any connectivity exists, but instead, I check the connectivity by pinging www.apple.com or www.google.com (because I coded it before this new API came to being – and since this API works only with iOS, I’d still need to ping www.google.com for Android…)

Anyhow, does anyone know if there’s other API I should look at to solve this problem? If no API can be used to solve it, does anyone know ways to solve this problem. I’d appreciate any and all suggestions, tips and pointers you might be able to offer.

Naomi

[import]uid: 67217 topic_id: 34766 reply_id: 334766[/import]

Possible workaround would be having a timer for each network request (say 30 seconds depending upon complexity) and if the request doesn’t happen within that time, cancel the request and inform the user that their connection speed isn’t sufficient? [import]uid: 33275 topic_id: 34766 reply_id: 138259[/import]

Hey, SegaBoy, thank you for the suggestion. You know, I have some network requests fire with delay using timers (but I set it with only 100 milliseconds delay.) Maybe giving them much longer delay might help. Maybe the ones that are not set up with timer delay are the culprit of this problem. Unfortunately, it isn’t so easy to test this because I can’t find an environment near me where the internet connectivity is always unreliable – so I wouldn’t be able to tell if it solves the problem or not…

About timing out the network.request, I do for the ones that the app waits responses from the server. The network requests that I have the native activity indicator set to true get cancelled when it takes too long and once cancelled, the app proceeds to the next step. This seems to work fine. The problem is with the ones that doesn’t require the app to wait for the response (and because the app doesn’t need response before proceeding to the next step, I don’t have the activity indicator set to true for those).

Anyhow, thanks again for your feedback. I might just have to lengthen the delay, add delay to network.request that doesn’t have one, and hope for the best.

Naomi [import]uid: 67217 topic_id: 34766 reply_id: 138307[/import]

Naomi - Just a quick suggestion – You mentioned " it isn’t so easy to test this because I can’t find an environment near me where the internet connectivity is always unreliable"…

An unreliable connection is closer, and more testing friendly than you might realize…

I’m using an iPad 3 (iOS 6.0.1), and in settings:developer there is a “network conditioner”… I highly recommend you give it a try… There is a default setting for “Very Bad Network” which has bad latency, and packet loss which can really stress your app. Also you can manually crank the settings as well, for higher packet loss, etc.

And the best part is, you can turn it off, run your app to the point where you want to test it (all nice and fast), and then turn it back on (the network conditioner) to test a specific spot in your app.

(as a note: I didn’t have the “Developer” option in my iOS settings until after I setup the device for dev in xcode) [import]uid: 79933 topic_id: 34766 reply_id: 138313[/import]

Hey, @mpappas, thank you for the info. That is awesome. Glad to know… And yes! I see the Developer under Settings on my iPod Touch too! I didn’t see it first, but after I tethered the device and launched Xcode, it showed up – and disconnecting the device didn’t hide the Developer option from the Settings. How interesting. Thanks again!

Naomi [import]uid: 67217 topic_id: 34766 reply_id: 138332[/import]

Possible workaround would be having a timer for each network request (say 30 seconds depending upon complexity) and if the request doesn’t happen within that time, cancel the request and inform the user that their connection speed isn’t sufficient? [import]uid: 33275 topic_id: 34766 reply_id: 138259[/import]

Hey, SegaBoy, thank you for the suggestion. You know, I have some network requests fire with delay using timers (but I set it with only 100 milliseconds delay.) Maybe giving them much longer delay might help. Maybe the ones that are not set up with timer delay are the culprit of this problem. Unfortunately, it isn’t so easy to test this because I can’t find an environment near me where the internet connectivity is always unreliable – so I wouldn’t be able to tell if it solves the problem or not…

About timing out the network.request, I do for the ones that the app waits responses from the server. The network requests that I have the native activity indicator set to true get cancelled when it takes too long and once cancelled, the app proceeds to the next step. This seems to work fine. The problem is with the ones that doesn’t require the app to wait for the response (and because the app doesn’t need response before proceeding to the next step, I don’t have the activity indicator set to true for those).

Anyhow, thanks again for your feedback. I might just have to lengthen the delay, add delay to network.request that doesn’t have one, and hope for the best.

Naomi [import]uid: 67217 topic_id: 34766 reply_id: 138307[/import]

Naomi - Just a quick suggestion – You mentioned " it isn’t so easy to test this because I can’t find an environment near me where the internet connectivity is always unreliable"…

An unreliable connection is closer, and more testing friendly than you might realize…

I’m using an iPad 3 (iOS 6.0.1), and in settings:developer there is a “network conditioner”… I highly recommend you give it a try… There is a default setting for “Very Bad Network” which has bad latency, and packet loss which can really stress your app. Also you can manually crank the settings as well, for higher packet loss, etc.

And the best part is, you can turn it off, run your app to the point where you want to test it (all nice and fast), and then turn it back on (the network conditioner) to test a specific spot in your app.

(as a note: I didn’t have the “Developer” option in my iOS settings until after I setup the device for dev in xcode) [import]uid: 79933 topic_id: 34766 reply_id: 138313[/import]

Hey, @mpappas, thank you for the info. That is awesome. Glad to know… And yes! I see the Developer under Settings on my iPod Touch too! I didn’t see it first, but after I tethered the device and launched Xcode, it showed up – and disconnecting the device didn’t hide the Developer option from the Settings. How interesting. Thanks again!

Naomi [import]uid: 67217 topic_id: 34766 reply_id: 138332[/import]