Check For Internet Connection

That’s right, it uses seconds.  In addition, I’ve found it helpful to use the ‘t’ option mentioned on that page, like this:

[lua]

settimeout(1, ‘t’)

[/lua]

This way the timeout applies to the entire networking attempt, and not just each operation that LuaSocket performs.

  • Andrew

Wont that interfere with any network.request i’m using? Because I dont want my original network.requests timeout by this option.

Hi there,

I don’t think it would interfere, since the timeout you set for this socket test is independent of the timeout you set for network.requests.

  • Andrew

For anyone using the socket method: http://w3.impa.br/~diego/software/luasocket/tcp.html#settimeout

I had some serious problems, the settimeout uses seconds not miliseconds  :slight_smile:

Use:

settimeout(1) -- sets timeout to 1 second  

That’s right, it uses seconds.  In addition, I’ve found it helpful to use the ‘t’ option mentioned on that page, like this:

[lua]

settimeout(1, ‘t’)

[/lua]

This way the timeout applies to the entire networking attempt, and not just each operation that LuaSocket performs.

  • Andrew

Wont that interfere with any network.request i’m using? Because I dont want my original network.requests timeout by this option.

Hi there,

I don’t think it would interfere, since the timeout you set for this socket test is independent of the timeout you set for network.requests.

  • Andrew

do you guys block access to your game when Internet connection isn’t available?

No, I just alert the user when they take an action that requires the internet (e.g., facebook, in-app purchase) that they need to have an internet connection.

  • Andrew

do you guys block access to your game when Internet connection isn’t available?

No, I just alert the user when they take an action that requires the internet (e.g., facebook, in-app purchase) that they need to have an internet connection.

  • Andrew

I know it’s a bit late, but I created a quick and easy library to check for internet connection. Maybe it’ll be helpful to some people that find this topic in a search: http://igaret.com/tutorials/test-internet-connection-corona-sdk

I know it’s a bit late, but I created a quick and easy library to check for internet connection. Maybe it’ll be helpful to some people that find this topic in a search: http://igaret.com/tutorials/test-internet-connection-corona-sdk

Garet, thanks for the code!

It saved me precious time :slight_smile:

FYI, using checking the internet connection with socket.tcp will work great ONLY if you have either no internet connection or a good internet connection.

If you have a flaky internet connection (such as a slow connection or a wifi signal whose router has disconnected from the internet) your app will freeze for several seconds. Sometimes up to 30 seconds.

Jorge

Garet, thanks for the code!

It saved me precious time :slight_smile:

FYI, using checking the internet connection with socket.tcp will work great ONLY if you have either no internet connection or a good internet connection.

If you have a flaky internet connection (such as a slow connection or a wifi signal whose router has disconnected from the internet) your app will freeze for several seconds. Sometimes up to 30 seconds.

Jorge

Hi Guys,

Did you find a solution to avoid freezing app?

I noticed that with the code above, Xcode console shows this message each second :

WiFi:[419334385.238658]: 

Too frequent(3.034801 secs) rssi event from driver

As if checking for internet connexion periodically

Can’t we check only one time and then stop the loop?

Thanks for your help

Best,

Olivier

Hi Guys,

Did you find a solution to avoid freezing app?

I noticed that with the code above, Xcode console shows this message each second :

 

WiFi:[419334385.238658]: 

Too frequent(3.034801 secs) rssi event from driver

 

As if checking for internet connexion periodically

Can’t we check only  one time  and then stop the loop?

 

Thanks for your help

Best,

 

Olivier

Hi there,

I don’t think you should place this code within a loop (such as a repeating timer.performWithDelay), especially at a frequency of one second.  If the socket takes more than one second to open and close, you’ll be opening more and more sockets to the same host, which is bad.

Instead, in my experience it’s worked well simply to wrap it in a function and call it to test network availability before critical user actions (such as attempting an IAP, attempting to share on social media, etc.), and alerting them if they don’t have a network connection.

  • Andrew