You need to test the network and see if it’s there before you call any plugin or network code that you need. On iOS we support a full suite of options to test network connectivity. See: https://docs.coronalabs.com/api/event/networkStatus/index.html
But on other platforms, you basically have to do it the old-fashioned way and try connecting to a server somewhere and see if you get a connection or not.
local socket = require("socket") local http = require("socket.http") local ltn12 = require("ltn12") function testNetworkConnection() print("testing connection") if http.request( "http://google.com/" ) == nil then print("cant connect to google") return false end print("got a connection") return true end
You can connect to your own server or any server that should be up. It should connect pretty quickly. If it can’t connect it should time out in a second or so…
Rob