add write ping before pinghandler starts
This commit is contained in:
@@ -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()
|
||||
|
Reference in New Issue
Block a user