增加WebSocket的ping包

This commit is contained in:
Erope 2021-04-04 00:22:50 +08:00
parent 1fa9fb0b48
commit ab9dfbc578

View File

@ -185,6 +185,7 @@ func (cp *commonPage) ws(c *gin.Context) {
return
}
defer conn.Close()
count := 0
for {
dao.SortedServerLock.RLock()
err = conn.WriteJSON(dao.SortedServerList)
@ -192,6 +193,10 @@ func (cp *commonPage) ws(c *gin.Context) {
if err != nil {
break
}
count += 1
if count%4 == 0 {
conn.WriteMessage(websocket.PingMessage, []byte{})
}
time.Sleep(time.Second * 2)
}
}