diff --git a/websocket/models/client.go b/websocket/models/client.go index 7c0667f..952972c 100644 --- a/websocket/models/client.go +++ b/websocket/models/client.go @@ -20,7 +20,7 @@ const ( writeWait = 30 * time.Second // Time allowed to read the next pong message from the peer. - pongWait = 30 * time.Second + pongWait = 40 * time.Second // Send pings to peer with this period. Must be less than pongWait. pingPeriod = (pongWait * 9) / 10 @@ -162,6 +162,10 @@ func (c *Client) PingInterval(interval time.Duration) { ticker := time.NewTicker(interval) defer ticker.Stop() + if err := c.conn.WriteControl(websocket.PingMessage, []byte("ping"), time.Now().Add(pongWait)); err != nil { + c.OnError(err) + return + } for range ticker.C { if c.OnPing != nil { c.OnPing()