Check for Internet in Corona SDK

Checking for the Internet before accessing the Internet data is the right way to do in any app that you make in any platform.

Here is a small gist to make the network check on Corona SDK. Either use the code in the same Lua file you use or use a separate utility lua file to add the functions. Check here for making the Utility file in Corona SDK (Lua).

Network Listener and network check using Sockets

Usage :

In the function where you want to check for the utility, just call the function, which will return you the network status.

Usage of Network function

Code Explanation :

1 — create a local variable.

2 — Create a network listener function available in the network library. Note that this will work only on iOS, so we are using sockets for Android.

3 — we are checking for the Platform and if its iOS, we are sending the status using the network listener which automatically changes the value of the isNetworkAvailable variable.

4 — Using the Sockets to check the internet connection if the platform is Android.

5 — Based on the Socket test result, we are setting the value for the isNetworkAvailable variable.

6 — Close the test connection

7 — return the isNetworkAvailable Variable.

That's for the Network. Happy coding!

📱 Mobile Developers Café

We talk about iOS, Android, Flutter and Mobile design.

Ranjithkumar Matheswaran

Written by

Subscribe to my weekly newsletter at @MobDevsCafe. iOS Developer & UI/UX Designer. Mountain Hiking, Driving, Roadtrips & Photography.

📱 Mobile Developers Café

A brand new page started to help mobile developers to get hang of whats happening in the community. Starting from mobile development articles, events, podcast, design inspirations, meetups, webinars and news, we would post everything that could help the community in some way.

Ranjithkumar Matheswaran

Written by

Subscribe to my weekly newsletter at @MobDevsCafe. iOS Developer & UI/UX Designer. Mountain Hiking, Driving, Roadtrips & Photography.

📱 Mobile Developers Café

A brand new page started to help mobile developers to get hang of whats happening in the community. Starting from mobile development articles, events, podcast, design inspirations, meetups, webinars and news, we would post everything that could help the community in some way.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store