I am using WebSockets Server on ESP8266 from here: GitHub – Links2004/arduinoWebSockets: arduinoWebSockets
Classical schema, nothing overcomplicated: client is written on JavaScript, running on browser, used to control ESP8266 device. I am using WSServer.broadcastTXT() to send json messages back to clients to update their webpage. Everything working very good for days, until problem happened.
Problem: If client is gone (for example, client cell phone has lost wifi) – web socket server takes very long time, around 20 minutes (!), to disconnect missing client. I see the call of WSServer.broadcastTXT() takes more than WEBSOCKETS_TCP_TIMEOUT mS, which is clearly understandable, but how to make the disconnection to trigger faster than these 20 minutes? Using WSServer.enableHeartbeat() with tight timing, like WSServer.enableHeartbeat(30000, 100, 3), does not change anything, except adding extra network traffic for ping-pong messages. If client just close page in browser – client closes correctly.
Is there any solution on how to enforce web socket server to disconnect missing client much earlier than 20 minutes? What is the logic of disconnection of client(s) on server side?