Best way to control the internet connection

Hello

Currently controlling the connection as such:

function M.checksInternetConnection() local socket = require("socket") local test = socket.tcp() test:settimeout(1, 't') -- Set timeout to 1 second local testResult = test:connect("www.google.com", 80) local thereIs if not(testResult == nil) then print("Internet access is available") thereIs = true else print("Internet access is not available") thereIs = false end test:close() test = nil return thereIs end

But on the forum I’ve seen a lot of complaints and I actually think it sometimes blocks the app for several seconds.

So what is the best way to make sure that we have access to internet?

Please read this thread: https://forums.coronalabs.com/topic/69687-advertising-request-with-internet-off/

Rob

Thanks, but one thing is not clear to me:

In the end, just modify my code with this:

local socket = require("socket") local client, err = socket:connect("www.google.com",80) client:settimeout(1,"t") -- too late, no effect local socket = require("socket") local master = socket.tcp() master:settimeout(1,"t") local client, err = master:connect("www.google.com",80) -- will use master's timeout

Or it is better to send a request to your own server?

Unless you have the resources of Google, there isn’t a much better site that can respond quickly. Scott Harrison mentioned a plugin in that thread, I think it’s his “More Info” plugin that has a realtime checker that may be better than trying to create  your own.

Rob

The More Info plugin handles this wonderfully, in my experience. Way easier than trying to build your own method IMHO.

https://marketplace.coronalabs.com/plugin/more-info

Brent

Thanks, brent. 

Thanks to the support. Try to use the plunger

Please read this thread: https://forums.coronalabs.com/topic/69687-advertising-request-with-internet-off/

Rob

Thanks, but one thing is not clear to me:

In the end, just modify my code with this:

local socket = require("socket") local client, err = socket:connect("www.google.com",80) client:settimeout(1,"t") -- too late, no effect local socket = require("socket") local master = socket.tcp() master:settimeout(1,"t") local client, err = master:connect("www.google.com",80) -- will use master's timeout

Or it is better to send a request to your own server?

Unless you have the resources of Google, there isn’t a much better site that can respond quickly. Scott Harrison mentioned a plugin in that thread, I think it’s his “More Info” plugin that has a realtime checker that may be better than trying to create  your own.

Rob

The More Info plugin handles this wonderfully, in my experience. Way easier than trying to build your own method IMHO.

https://marketplace.coronalabs.com/plugin/more-info

Brent

Thanks, brent. 

Thanks to the support. Try to use the plunger