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