Hi,
I am trying to use the github.com/gorilla/websocket
library of the Go language to code a WebSocket connection to obtain real-time information on spot and futures transactions.
I noticed that “The WebSocket server will send a ping frame every 3 minutes. If the WebSocket server does not receive a pong frame back from the connection within a 10 minute period, the connection will be disconnected. Unsolicited pong frames are allowed.” is mentioned in the document.
So, I tried the method:
msgType, _, err := w.conn.ReadMessage()
if err != nil {
logger.Error("Read error: %s", err)
time.Sleep(TimeIntervalSecond * time.Second)
continue
}
if msgType == websocket.PingMessage {
w.conn.WriteControl(websocket.PingMessage, []byte{}, time.Now().Add(10*time.Second))
} else {
}
However, I did not receive a WebSocket message of type ping. And without sending pong to the server, I can still get data from the server for several hours.
I searched the forum for similar issues:
Not receiving PING frame for Futures Websocket, as mentioned in their documentation
Not receiving ping frame from Binance for Websocket Futures Market Stream#7
But after a few months, the document does not seem to be updated. At present, do I need to set a timer to send pong messages to the server regularly, regardless of whether I receive the ping message sent by the server, or whether it is possible in the subsequent update, as stated in the document, “every 3 minutes or 5 minutes, the server sends pong messages to customers Send a ping message”, hope to receive your reply as soon as possible.
Thanks in advance.