Another problem:
I use Wemos D1. For connecting to WIFI I use the funtion wifi.connect2. But sometimes this function hangs forever. A reset by the button doesn't help. Only a power off/on helps. I checked this behaviour with two diffent Wemos (D1 mini pro and D1 R2).
With the line CallSubPlus("CloseConnection", 200, 0) I don't have this issue, but then I have the other issue. Strange! I can decide between problem A and problem B, but I don't need anything of it...
WiFi.Connect / Connect2 are blocking methods. Internally they wait for the connection result and only then they return. If there is no result for some reason then they will not return.
I think that's the solution. Until now I don't have this long waiting problems and I hope it will remain like that .
BTW: I deleted a debug line in your code: "available" in checkForClient.