I’m using the simplest code to detect for an internet connection, and I’ve been testing it in various situations.
[lua]function internetAvailable()
local connectAttempt = require(‘socket’).connect(‘google.com’, 80)
if connectAttempt == nil then
debug(“Unble to establish internet connection”)
return false
end
debug(“Able to establish internet connection”)
connectAttempt:close()
return true
end[/lua]
In certain situations, i.e. there’s Wi-Fi but no internet, the app will completely hang.
Has anyone come up with a better solution? [import]uid: 6084 topic_id: 7291 reply_id: 307291[/import]
(Just wanted to add an aside: google.com may be blocked in certain countries at certain times. Just in case thise sidenote may be useful to the code you end up with.) [import]uid: 10284 topic_id: 7291 reply_id: 25643[/import]
As just a swag, i’m betting this has something to do with timeout/blocking. Look into setting it to .0001 or perhaps 0 [import]uid: 6175 topic_id: 7291 reply_id: 25829[/import]
Would you mind using the timeout in my example code above? I’d like to know how and where to place it. [import]uid: 6084 topic_id: 7291 reply_id: 28736[/import]