Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!
I'd like to be able to check for an internet connection. I have a green image and a red image. Green when connected, red when disconnected. So if my wifi is enabled I'd like to see green, when disabled a red image. Here's my code:
add 1 to tCount
put URL ("google.com?count=" & tCount) into pURL
get URL pURL
put the result into tResult
if tResult is not empty then
put "disconnected" && tResult into field "fldStatus"
show image "imageRed"
hide image "imageGreen"
return false
else
put "connected" into field "fldStatus"
show image "imageGreen"
hide image "imageRed"
end if
Well, if I put the code in the pre openCard it works. The problem is that I have to close the app to get the script to run again when a connection is present. Hmmmm.
put URL ("http://www.google.com?timestamp=" & the millisecs) into pURL
I'm not completely sure that that is the correct way to write it.
It should get you a fresh page every time and assure you are actually online.
Simon
Thanks Simon. I'll explore that further too. I had the following, but that wouldn't work for me. Maybe I had the parenthesis in the wrong spot. I had...
Simon wrote "I recall you have to watch out for pulling up a cached version of the web page so:"... not in what is happening here as the load command is not being used...
The issue sometimes crops up if the url is being cached (where? no clue) so hitting the same url doesn't really do so. Have had it happen to me (not using load) and the easiest answer was like simon suggested, tack on a changing value to the url so a new fetch occurs each time.
Dixie wrote:Simon wrote "I recall you have to watch out for pulling up a cached version of the web page so:"... not in what is happening here as the load command is not being used...
function checkConnexion
put ("http://www.google.com/?x=" & the millisec) into pURL
put url (pURL) into pURL
if pURL is empty then
return false
else
return true
end if
end checkConnexion
If the connexion is not active, just few seconds, Livecode return always false even when the connexion come back. And even if i change the url with
Hi ludo,
Go ahead and remove that put url (pURL) into pURL and just use:
put URL("http://www.google.com/?x=" & the millisec) into pURL
(note the "put URL") save you a step.
Other than that how often are you hitting google? I think you may be polling it? Face it, everybody and their uncle are using it to test connections. Better to use the actual source website you are downloading from (I put up a small text file and check the actual content).
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
Simon wrote:Hi ludo,
Go ahead and remove that put url (pURL) into pURL and just use:
put URL("http://www.google.com/?x=" & the millisec) into pURL
(note the "put URL") save you a step.
This step is just to debug and saw that the url change every time.
Other than that how often are you hitting google? I think you may be polling it? Face it, everybody and their uncle are using it to test connections. Better to use the actual source website you are downloading from (I put up a small text file and check the actual content).
It could be severals minutes between the check. And even if i change the url to an other domain (like yahoo) it return false ! But if the command put URL() return always empty, revBrowser work ! After quit and reopen Livecode it's work...
Maybe a bug ?