Testing if internet conenction exists ?

What is the best way to test if there is internet connection in Corona ?
Regards,
Damir. [import]uid: 108334 topic_id: 25940 reply_id: 325940[/import]

Corona SDK supports network status testing through the use of the network.setStatusListener API call. See:

http://developer.anscamobile.com/node/10090

However I use a very cheesy way of doing my own test:

local function networkListener(event)  
 if ( event.isError ) then  
 --print("offline")  
 \_G.online = false  
 else  
 --print("online")  
 \_G.online = true  
 authorize() -- starts the whole GameCenter login process  
 -- you can do whatever you need to do once you know  
 -- you have a network connection  
 end  
 storyboard.gotoScene("splash")  
end  
  
network.download("http://omnigeekmedia.com/ping.txt", "GET", networkListener, "ping.txt", system.TemporaryDirectory)  

Please if you use this, respect my bandwidth and use your own ping.txt file on your own web server.
[import]uid: 19626 topic_id: 25940 reply_id: 104988[/import]

Or you can just ping google :smiley:

[lua]local socket = require “socket”
local function testNetworkConnection()
local netConn = socket.connect(‘www.google.com’, 80)
if netConn == nil then
return false
end
netConn:close()
return true
end

local isNetActive = testNetworkConnection()[/lua] [import]uid: 64174 topic_id: 25940 reply_id: 105039[/import]

I like Both ways they are short and to the point :slight_smile:

Larry [import]uid: 11860 topic_id: 25940 reply_id: 105624[/import]