testing for Internet connection
Chipp Walters
chipp at chipp.com
Sun Dec 19 05:01:03 EST 2004
Hi Richard,
I've found this to work well:
function isConnectedToInternet pURL
if pURL is empty then put "http://www.google.com" into pURL
get URL pURL
put the result into tResult
if tResult is not empty then
answer information "Problem connecting to the internet: "& tResult
return false
else
return true
end if
end isConnectedToInternet
a more elaborate variant I use which compensates for long latency
connections like satellite or some dialups:
function altIsConnected pURL
--> STORES IN DEBUG FLD IN ALTINTERNET LIBRARY
altDebug "checking internet connection to:",pURL
--> TURNS ON ANIMATED BUSY.GIF
ImBusy true
put 0 into x
repeat 5 times
add 1 to x
altDebug "Trying to GET from URL:",pURL && "try " & x
put URL pURL into pData
put the result into tResult
if tResult is not empty then
answer tResult
altDebug "Result from GET:",tResult
exit repeat
end if
altDebug "Result from pURL:",pData
if pData is not empty then
--> YOU CAN PUT COMMON PROXY AND FIREWALL AUTHENTICATION CODE HERE
switch
case "WatchGuard" is in it --WatchGuard firewall
break
default
ImBusy false
return true
end switch
end if
end repeat
altDebug "Could not connect to Server after " &x& " tries."
answer "Cannot connect to: " & pURL &cr& tResult
ImBusy false
return false
end altIsConnected
if your user is not connected, they will probably get an 'invalid host'
answer. Testing against google seems always to work for me. I figure, if
they can't get to google, then they can't get to my server.
-Chipp
Richard Gaskin wrote:
> There have been many posts here over the last couple years about
> various methods of having an app test to see if it has an Internet
> connection available, but for every suggestion I can find in the
> archives there's a subsequent post explaining why that method isn't
> optimal or in some cases even reliable.
More information about the use-livecode
mailing list