Web Sockets Server - disappeared client does not disconnected

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 web-page. 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 that? 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.

Are 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?

I use ws.cleanupClients(1); to get rid of old connections. ws is a AsyncWebSocket. This does not take care of all bad browser behaviour but most of the time it works.

I am not using AsyncWebSocket, it is another library, I have mentioned it in first sentence. And library I use does not have cleanupClients() method. And according to documentation, the cleanupClients() method in AsyncWebSocket library does not perform what I am asking about...

Yes, but you want a Solution. With AsyncWebServer and AsyncWebSockets it works. And you are free to program a trigger yourself.

My question was about specific library, supposing bug in it or my misunderstanding of its operation. You offer me as a "Solution" to use another library (which will enforce me to overwrite whole related code) and you reference the function which is, according to documentation and source code, have nothing to do with my problem. Ok, thank you, may be your recommended library does not demonstrate at all the problem I observe, but if so - seems like it is not due to function you have mentioned. I will look on this library. thank you again, but it will be the last what I will try.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.