Question re download timeout setting

Alex Tweedly alex at tweedly.net
Sat Jul 22 07:45:00 EDT 2023


On 22/07/2023 04:29, Bob Sneidar via use-livecode wrote:
> Use sockets to test the connection.
>
> Open socket to <url:port>
> If the result is not empty then…
> Close socket <url:port>

Hmmm - I have tried it but not got reliable results.

According to the dictionary that won't work reliably. Dictionary says:

> (4.5) The open socket command no longer blocks on DNS resolution.
>
> Instead, if resolution is required the command will return immediately
>
> and the DNS lookup will happen in the background. If resolution fails,
>
> then a socketError message is sent in the same was as if connection
>
> fails.
>
So if you need a DNS resolution, you'll get an empty result - and a 
later socketError message. Your suggested code takes the empty result as 
a sign things are working - when they may not be.

(When I try to connect to a non existent host:port, I do get the empty 
result, but I don't seem to be getting the socketError messages. So 
there may be a bug in there - I'll try to track it down more closely, 
and if I can get anything reliable, submit a bug report).

btw - livekode.com was my first attempt at a  "non-existent host" - and 
it does exist !!

Alex.

>> On Jul 21, 2023, at 17:49, Alex Tweedly via use-livecode <use-livecode at lists.runrev.com> wrote:
>>
>> 
>>> On 22/07/2023 01:02, prothero--- via use-livecode wrote:
>>> Folks:
>>> Sorry for the trivial question, but..
>>> I have an app on my iphone that I am updating from a several years old app the previously worked on an older version of livecode. It needs to access a mysql database on the internet. It works fine when there is internet service.
>>>
>>> I test access by downloading a file with a simple text code. If there code is returned in the message, I continue accessing the database. However, when there is no internet, the "put URL” command seems to hang forever. I’ve looked for a way to set the timeout for an internet command, but…. can’t,.
>>>
>>> Could you direct me to a simple explanation about how to set a reasonable internet not connected message?
>>>
>> .... not thoroughly tested ....
>>
>> You should, I think, be able to do this using tsNetSetTimeouts. But I wouldn't :-)
>>
>> I'd do something like the following - I've tested some, but not all, failure cases, but haven't tested a successful url.
>>
>>
>>> local sEventID
>>>
>>> -- neverhappens.com is a website - returns "Forbidden"
>>> -- nevehapens.com isn't, so almost immediately returns "can't be reached"
>>> -- I didn't test a properly working case :-)
>>>
>>> constant KURL = "http://neverhappens.com"
>>>
>>> on mouseup
>>>     load url kURL with message "gotareply"
>>>     send "timetocheck failed" to me in 10 seconds     -- or whatever timeout you want
>>>     put the result into sEventID
>>> end mouseup
>>>
>>> on gotareply pURL, pURLStatus
>>>     cancel sEventID
>>>     timetocheck pURLStatus
>>> end gotareply
>>>
>>> on timetocheck pWhat
>>>     local tAnswer
>>>     put "time to check" && pWhat &CR after msg
>>>     if pWhat = "loaded" then
>>>        put URL kURL into tAnswer
>>>        if tAnswer contains "mycode" then
>>>           -- Internet is good
>>>           put "Internet is good" &CR after msg
>>>        end if
>>>     end if
>>>     -- Internet problematic
>>>     put "problem" &CR after msg
>>>     if pWhat = "error" then put libUrlErrorData(kURL) &CR after msg
>>>
>>>     unload URL KURL
>>> end timetocheck
>>
>> Alex.
>>
>>
>> _______________________________________________
>> 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
> _______________________________________________
> 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