Skip to content

Commit

Permalink
Fixes #9 - Replaced conn.WriteMessage with conn.WriteControl
Browse files Browse the repository at this point in the history
  • Loading branch information
pkcs8 committed Sep 22, 2024
1 parent 4e11916 commit 0de3c92
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ func (c *Client) NewConnection() (*websocket.Conn, error) {
c.closed = false

// Set connection handlers and heartbeat
c.connection.SetReadDeadline(time.Now().Add(c.config.ReadTimeout * time.Second))
c.connection.SetPongHandler(c.handlePong)
go c.handleResponse()
go c.heartbeat()
Expand Down Expand Up @@ -161,7 +162,8 @@ func (c *Client) Ping(message []byte) error {
c.mutex.Lock()
defer c.mutex.Unlock()
// log.Println("PING:", string(message))
if err := c.connection.WriteMessage(websocket.PingMessage, message); err != nil {
newDeadline := time.Now().Add(c.config.WriteTimeout * time.Second)
if err := c.connection.WriteControl(websocket.PingMessage, message, newDeadline); err != nil {
return err
}
return nil
Expand Down

0 comments on commit 0de3c92

Please sign in to comment.