Check connection and timeout
bobsneidar at iotecdigital.com
Fri Jul 14 12:21:34 EDT 2023
I use a simple method of sockets to determine if I have a connection to a host. I close the socket first:
Then I open the socket:
Open socket to 127.0.0.1:3306
Put the result into tError
If terror begins with “ERROR: “ then
— your code here
Then close the socket again.
Close socket 127.0.0.1:3306
I find this to be the most reliable way to check a connection. I may not have internet, but the host may not be on the internet it may be local. Also, sockets will always work whereas ICMP can be blocked by a firewall. And simply trying to connect to a host will, as you have noticed bring timeouts into play.
> On Jul 13, 2023, at 11:26 PM, Ludovic THEBAULT via use-livecode <use-livecode at lists.runrev.com> wrote:
> I use this code to check is there is an internet connection :
> tsNETSETTIMEOUTS 60,0,2000,60000,5,1000
> put tsNetHeadSync("https://google.com/", tHeaders, tResult, tBytes) into tRecvHeaders
> if tResult begins with "tsneterr:" then
> return false
> return true
> end if
> But the setting for the timeout of tsNETSETTIMEOUTS is not active, I always have a 30 seconds timeout.
> Is there an other settings ?
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
More information about the use-livecode