Closed ChiefyChief23 closed 4 years ago
The server could be disconnecting the client after some time. Consider adding pings on fixed intervals in either the client or server code.
Also, when the client disconnects try printing the error reason. Have a look here for more info: https://github.com/gilmaimon/TinyWebsockets/wiki/Client#Close-Reason-Codes
When the esp32 disconnects, how do you reconnect it?
It's actually occurring when connecting to the server and the server has other machines, not ESP32 but Windows running WebSocket clients, which have no issue what so ever connecting to the main WebSocket server. So it seems weird how the ESP32 is unable to connect whilst other are?
I've actually recently added ping capability to the ESP32 in order to hopefully open up the connection reliably and also increased logging around the ping to ensure if its working or not but this implementation will be on the system within the week.
I'll include the disconnect reason codes in because it may highlight something but like I said the issue is prior to actually connecting. Once they are connected though, everything works perfectly. Messages being sent instantaneously, no fragmentation, its perfect (so kudos on that part for the great library!) but this connection problem has been plaguing me for a while and I've run out of ideas to what could be happening.
When the ESP32 disconnects/fails to connect it effectively tries again after a delay of a few seconds and to ensure there isn't anything lingering on the heap which could be blocking it I enforce a hard restart of the system so it replicates me powering up the ESP32 on the development side to try and keep things under the same condition.
It's hard for me to figure out the issue here.
Maybe try reproducing on the most verbose esp32 logging level, and also log the disconnect reason.
Sharing the code might also help. Also, you could try adding logs to the library itself in some key point, that might help you debug this a bit, as I think it would be hard for me to reproduce your environment.
Gil.
I made this issue as a stab in the dark in the hopes it was a potential known issue. However, given that it isn't and it's a difficult problem to reproduce I'm going to assume from here on out it's a non-coding issue and going to look at other parts of the system. I appreciate your thoughts and apologies if I wasted your time.
Closing issue.
Don't be silly @ChiefyChief23, you didn't waste my time! This could be an issue with the library, and even if it's an environmental issue I'm happy to help as much as I can. Feel free to re-open this issue if you want, or consult with me via email. I'm just sorry I can't be more helpful, my time is limited and sadly there isn't enough for me to provide good support to all issues here as well as working on other project..
I can also suggest:
Gil.
I have a Windows 10 machine running a WebSocket server (just denote as server from here on) and I have a ESP32 with a WebSocket client (just denote as client from here on).
In general, the client will connect to the server without any issues but sometimes, without any indication of what is causing it will "struggle" to connect as if the server isn't running or something (it is, I can connect using a browser WS client and no issues there). On occasion when this happens after a certain amount of time the client will miraculously just connect (which is very puzzling because I do nothing just time passes).
I initially thought I solved the problem by adding rules to the Windows firewall to ensure all incoming/outgoing connections for the port that the actual WebSocket server is using is always allowed. This however, didn't solve it.
One weird thing however, is if the client is in this "phase" of trying to connect to the server and not being able to and I ping the client, just using powershell, on it's LAN IP from the server itself then the connection just kind of opens up and works. This fix has been re-producable too, to the point of thinking about including a Pinger class using Boost to ping the clients if they haven't connected within a certain time.
Because of the ping fix I've also added extra firewall rules to allow all ICMPv4 and ICMPv6 echo requests on all connections at all times. This also did not work.
Finally, I also completely turned off the firewall. This did not work...
Why is this happening?
Extra info:
Server uses: Websocketpp Client uses: ArduinoWebSockets IDE: Visual Studio with VisualGDB
When connected it works perfectly, i.e. the sending of messages, handling them, and replying. It's just the connection seems to be a bit tricky for the ESP32 for some reason.