Irregular websocket ping/pong behaviour


I am using websocket streams for trades, tickers and user data. I want to be sure all streams are always connected and remain connected. In order to check this, I have built a reconnection system, which checks every x minutes whether or not a ping or pong has been received in the minutes before it. If it has been too long ago, the websocket will close and try to reconnect. This system works fine, but I am noticing some irregular behaviour here.

Sometimes, I receive pings and pongs successfully for multiple hours in a row, but then all of a sudden, they stop coming in, which is where my reconnection system comes in. Is this common or is there another reliable way to check if the connection is still active?

Thanks in advance.

Hi @StalexB, thanks for your feedback.

Ping Pong is the correct and recommend way at Binance for validating the connection healthy. Our server follows the protocol and response to pong as soon as possible.

For some cases that pong is not received, it’s sign that the connection is not active anymore, it’s a good idea to reconnect from client. But how the connection is broken, there are many variables. I would suggest to test more and find the clue from the logs.

We are here to help for any concern. :slight_smile:

thank you.