Any good, timely way to test for server availability?

I have created a “control panel” UI in KLWP that displays/controls a server on a remote machine that has an open http port on 5001. That server may not be running at a given time (indeed one thing the control panel does is permit stop/start of the server) and I need to know, in a timely fashion, if the server is reachable/running.

My first approach was to use $wg(“http://IP:port”, raw)$ in a formula for a global variable. But I see two problems with this:

(a) I don’t know what the standard interval is for KLWP to refesh the variable and it may not be frequent enough. I have read about and tried putting the wg() inside a tu(seq) in an effort to force more frequent updates. But it doesn’t appear I am doing that right or it doesn’t work.

(b) the $wg()$ function seems to use a cache and so if the server is not reachable, it appears to return something anyhow and that defeats my purpose.

So I considered using a flow as I understand the wget action in flows do NOT use a cache. I can do this and it would be fine. I could run it on a cron. But it seems like the best I can do with the flow cron mechanism is to trigger once every 2 minutes. using “*/2 * * * *”. That is fine for many things but not frequent enough for this. I am no cron expert so maybe I can do better somehow?

So now I am considering other possibilities:

I realize that part of this is easily done using nc() stuff. Clearly, if there is no connection, there is no way to reach the server. But my phone could have connectivity in general but still not be able to reach the server IP. I can shell out to ping to test that, I guess.

The hard part for me is to test if the port is available. As my phone is rooted and has busybox installed, I can telnet to the IP/Port and find out that way. But that will not work on my wife’s phone, for example, which is NOT rooted.

So I am trolling for another approach and appreciate your help/ideas. Thanks

I MAY have come up with a decent solution on my own… Combine elements that I mentioned earlier…

  1. Create a flow triggered by a change in a formula output. Use $tu(seq, 1/4, 1/ 100000000000)$ as the formula. This triggers a change every 15 seconds. The final term in the tu() is just a BIG number so…

  2. In the flow, use a web get action to http://IP:Port. If not available, it will fail and the flow terminates immediately.

  3. If the server is reached, the flow continues. Have it first execute a formula $sh(“date ‘+%s’”)$ and then store the result in a text global called LastChk.

  4. Create a text global called IsOnline based on the formula $if(sh(“date ‘+%s’”) - gv(LastChk) < 20, “t”, “f”)$ (just make sure the value tested for < is a 2-3+ seconds longer than the time utility’s interval in #1). Then have whatever needs to react to the online state simply check the value of the IsOnline global variable for t or f.

This is working pretty well.