Page 1 of 1
Checking internet connection is blocking
Posted: Fri Feb 07, 2020 12:09 am
by trevix
LC 9.6.0 DP2
OSX 10.14.6
Android 7
Trying to find out in a standalone if there is an internet connection, I am doing this on a function:
Code: Select all
put url "http://www.google.com" into tURL
if tUrl is empty then...no connection
While it works fine on OSX and iOS, on Android it locks the script for up to 30 seconds (I disabled wifi in order to test this).
I tried to add a
Code: Select all
set the socketTimeoutInterval to 1000
but apparently things don't change.
Off course, if I enable wifi, everything works fine.
Why is this? How differently can I do it?
Thankyou
Re: Checking internet connection is blocking
Posted: Fri Feb 07, 2020 10:20 am
by bogs
Heya Trevix,
You might try giving this
lesson a read, it explains the differences between 'put' and 'load' (blocking and non-blocking) url usage.
If you decide to continue to use 'put' instead, I think I'd check the result, instead of whether the variable has information or not. There might be any number of reasons aside from connectivity that would leave the variable empty, the result will tell you why it is empty.
Edited to give you a picture illustrating what I mean, This machine is obviously connected ( I am posting on it ), but duckduckgo doesn't load using Lc 6.5 because of the antiquity of protocol used in 6.5, not because the network is down.

- Just something to think about...
Re: Checking internet connection is blocking
Posted: Fri Feb 07, 2020 10:48 am
by trevix
Thanks for the help.
I think I solved as you suggested, putting this in the stack script:
Code: Select all
local sConnectionTrue = false
on OpenStack
if the environment is "development" and there is a stack "revStandaloneProgress" and the mode of stack "revStandaloneProgress" > 0 then
exit OpenStack
end if
breakpoint
put "No connection" into fld "FldResult"
send "CheckConnection" to me in 100 milliseconds
end OpenStack
command CheckConnection
put false into sConnectionTrue
repeat with U = 1 to 10
if sConnectionTrue then
put "Connected" into fld "FldResult"
beep
exit CheckConnection
end if
load URL ("http://www.google.com") with message "UrlReceived"
wait 500 milliseconds with messages
end repeat
put "No connection found" into fld "FldResult"
end CheckConnection
On UrlReceived pURL, pURLStatus
if pURLStatus is "cached" then
put true into sConnectionTrue
unload url pURL
else
put libURLErrorData(pURL) into theError
set the text of field "FldResult" to "An error occurred:" & cr & theError & "."
end if
end UrlReceived
Any further suggestions are welcomed.
Trevix