Check connection and timeout
Bob Sneidar
bobsneidar at iotecdigital.com
Fri Jul 14 12:21:34 EDT 2023
Hi Ludovic.
I use a simple method of sockets to determine if I have a connection to a host. I close the socket first:
closeSocket 127.0.0.1:3306
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
End if
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.
Bob S
> On Jul 13, 2023, at 11:26 PM, Ludovic THEBAULT via use-livecode <use-livecode at lists.runrev.com> wrote:
>
> Hello,
>
> 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
> else
> 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 ?
>
> Thanks.
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
More information about the use-livecode
mailing list