How to debug Server.isOnline()
-
I'm using Server.isOnline() to check for an internet connection before I perform some networks tasks. It's implemented in a function like this:
// Check Internet Connection function checkInternetConnection() { if(!Server.isOnline()) { sendEvent(ErrorCode.NO_INTERNET); return false; } return true; }
This is returning false on some users systems even though they have internet.
Server.isOnine() appears to just ping Google and Amazon as a test.bool ScriptingApi::Server::isOnline() { const char* urlsToTry[] = { "http://google.com/generate_204", "https://amazon.com", nullptr }; for (const char** url = urlsToTry; *url != nullptr; ++url) { URL u(*url); auto ms = Time::getMillisecondCounter(); std::unique_ptr<InputStream> in(u.createInputStream(false, nullptr, nullptr, String(), HISE_SCRIPT_SERVER_TIMEOUT, nullptr)); dynamic_cast<JavascriptProcessor*>(getScriptProcessor())->getScriptEngine()->extendTimeout(Time::getMillisecondCounter() - ms); if (in != nullptr) return true; } return false; }
So I've had the end users perform this task manually via command prompt, and they get a response.
curl -I http://google.com/generate_204 returns: HTTP/1.1 204 No Content Content-Length: 0 Cross-Origin-Resource-Policy: cross-origin Date: Wed, 03 Jan 2024 13:23:15 GMT and ping -c 4 google.com returns: Pinging google.com [142.250.81.238] with 32 bytes of data: Reply from 142.250.81.238: bytes=32 time=13ms TTL=116 Reply from 142.250.81.238: bytes=32 time=10ms TTL=116 Reply from 142.250.81.238: bytes=32 time=10ms TTL=116 Reply from 142.250.81.238: bytes=32 time=17ms TTL=116 Ping statistics for 142.250.81.238: Packets: Sent = 4, Received = 4, Lost = 0 (0% loss), Approximate round trip times in milli-seconds: Minimum = 10ms, Maximum = 17ms, Average = 12ms
It seems that they have an internet connection. What method can I use to gather information from the Server function to see where it's failing? Is there something similar to the Server Controller that can be tapped in to?
-
@Dan-Korneff Are those users in China?
-
@d-healey They are not in China. And the manual test shows that they can reach the isOnline endpoints.
-
@Dan-Korneff Have you set a short timeout value?
HISE_SCRIPT_SERVER_TIMEOUT=20000
-
What happens if you change the URL in the C++ code to use SSL:
"https://google.com/generate_204"
I know that sometimes on macOS there is an issue with connecting to non SSL domains.
-
@Christoph-Hart said in How to debug Server.isOnline():
I know that sometimes on macOS there is an issue with connecting to non SSL domains.
That might be why I did this