Another post resumed...
My standalone (iOS and Android) needs to know if the device is connected to internet and to obtain the public IP (not the local IP)
I had a script that was working fine, using "
http://ifconfig.me/ip". Then, on the last update, I realised that the website started to respond with the IPv6 instead of the IPV4, so I decided to use a different approach.
I uploaded a file to a web site with the following code that, when reached, supply a clean public IP.
Code: Select all
<html>
<head>
<title>PHP Test</title>
</head>
<body>
<?php echo 'User IP Address_'.$_SERVER['REMOTE_ADDR']; ?>
</body>
</html>
This is the LC script I am using:
Code: Select all
local sMyIP
on mouseUp pButtonNumber
set the visible of image "LoadingSpinner.gif" to true
put empty into sMyIP
load URL "https://www.referi.it/returnip.php" with message "CheckGetMyIPreceived"
repeat with U = 1 to 15
if sMyIP is not empty then
exit repeat
end if
wait 500 milliseconds with messages
end repeat
set the visible of image "LoadingSpinner.gif" to false
if sMyIP is not empty then
put lineOffset("User IP Address", sMyIP ) into tLineNum
set the itemdelimiter to "_"
answer word 1 of item 2 of line tLineNum of sMyIP
else
answer "no Internet"
end if
end mouseUp
command CheckGetMyIPreceived pURL, pURLStatus
if pURLStatus is "cached" then
put URL pURL into sMyIP
else
put empty into sMyIP
end if
unload url pURL
end CheckGetMyIPreceived
I need the standalone to be able to handle situations where the WiFi goes off or the SSID changes (the device connects to a different wifi).
Consider also:
- In my tests, I always gave enough time, after test disabling/enabling the wifi or connecting the device to a different router, before running the LC script.
- The script URL download should be "blocking", since the code after that depends on a positive wifi connection.
- I think that 6-10 seconds are a reasonable time after wich the script should decide that there is not a internet connection. More than that may have the user think that the app is hanging...
- I could not find any ready made way to change the timeout of the connection, since socketTimeOut apply to sockets only and tsNetSetTimeouts does not apply either
- For obvious reasons, the response behaviour on OSX, iOS and Android should be as similar as possible.
These are my findings:
--OSX 12.6.8
--change of SSID: erratic behaviour : first time reports no connection. Second time reports the new IP after a while.
--Wifi > nowifi as from loop, it takes 15x500 milliseconds to report no internet. Usefull if wifi strenght is low??
--nowifi >wifi: Ok
--iOS 16
--change of SSID: erratic behaviour : first time reports no connection. Second time reports the new IP after a while.
--Wifi > nowifi as from loop, it takes 15x500 milliseconds to report no internet. Usefull if wifi strenght is low??
--nowifi >wifi: Ok
--ANDROID 13
--change of SSID: as from loop, it takes 15x500 milliseconds to report no internet. Usefull if wifi strenght is low??
--Wifi > nowifi and nowifi >wifi works fine
So apparently everything works fine on Android, but not so much on OSX and iOS, which share a similar behaviour.
Any suggestions on this?
(I have tested other solutions but I will keep them for later on, since the above was the overall best one)
Regards
Trevix