luoyangwei 1 سال پیش
والد
کامیت
b5319e24d1
3فایلهای تغییر یافته به همراه3 افزوده شده و 11 حذف شده
  1. 2 4
      server/client.go
  2. 0 2
      server/server.go
  3. 1 5
      websocket.go

+ 2 - 4
server/client.go

@@ -29,9 +29,7 @@ type Client struct {
 
 	readWait  time.Duration // readWait 读超时
 	writeWait time.Duration // writeWait 写超时
-
-	pingWait time.Duration
-	pongWait time.Duration
+	pingWait  time.Duration // pingWait 心跳超时
 
 	repos *repositories.Repositories
 }
@@ -103,7 +101,7 @@ func (c *Client) reader() {
 			c.Send <- newReplyMessage(message)
 
 			// Reset read dead line, prevent Reader from shutting down
-			c.UnderlyingConn.SetReadDeadline(time.Now().Add(c.pongWait))
+			c.UnderlyingConn.SetReadDeadline(time.Now().Add(c.pingWait))
 		}
 	}
 }

+ 0 - 2
server/server.go

@@ -25,7 +25,6 @@ type Server struct {
 	ReadWait  time.Duration
 	WriteWait time.Duration
 	PingWait  time.Duration
-	PongWait  time.Duration
 }
 
 func WebsocketHandler(ctx *gin.Context, srv *Server) {
@@ -57,7 +56,6 @@ func WebsocketHandler(ctx *gin.Context, srv *Server) {
 		writeWait:      srv.WriteWait,
 		readWait:       srv.ReadWait,
 		pingWait:       srv.PingWait,
-		pongWait:       srv.PongWait,
 
 		isSimpleMsg:  headers[keys.SimpleHeader].(bool),
 		localization: headers[keys.LocalizationHeader].(string),

+ 1 - 5
websocket.go

@@ -50,11 +50,7 @@ func newApp() *gin.Engine {
 		},
 		WriteWait: 10 * time.Second,
 		ReadWait:  10 * time.Second,
-		PongWait:  20 * time.Second,
-		// 写 ping 帧周期(必须小于 pongWait), 54s
-		// PingWait:  (600 * time.Second) * 9 / 10,
-		// (pongWait * 9) / 10
-		PingWait: 13 * time.Second,
+		PingWait:  120 * time.Second,
 		Hub: server.NewHub(server.HubConfig{
 			ConnectSize:    1024,
 			DisconnectSize: 1024,