增加WebSocket的ping包
This commit is contained in:
		
							parent
							
								
									1fa9fb0b48
								
							
						
					
					
						commit
						ab9dfbc578
					
				@ -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)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user