Reliable way of checking for network connectivity

I’ve seen other posts on this topic but am yet to find a reliable solution that works.

For example:

http://developer.anscamobile.com/forum/2010/04/07/checking-wifi-3g

The solutions in this post worked the first time, but not reliably. [import]uid: 31718 topic_id: 7040 reply_id: 307040[/import]

http://developer.anscamobile.com/code/check-internet-connection#comment-13815

This works for me.

[lua]local function testNetworkConnection()
local google = require(‘socket’).connect(‘google.com’, 80)
if google == nil then
return false
end
google:close()
return true
end[/lua] [import]uid: 6084 topic_id: 7040 reply_id: 24656[/import]