Skip to content

Instantly share code, notes, and snippets.

@percybolmer
Created September 11, 2022 06:01
Show Gist options
  • Save percybolmer/1975c15ddcf9976120627b5262937abe to your computer and use it in GitHub Desktop.
Save percybolmer/1975c15ddcf9976120627b5262937abe to your computer and use it in GitHub Desktop.
// readMessages will start the client to read messages and handle them
// appropriatly.
// This is suppose to be ran as a goroutine
func (c *Client) readMessages() {
defer func() {
// Graceful Close the Connection once this
// function is done
c.manager.removeClient(c)
}()
// Set Max Size of Messages in Bytes
c.connection.SetReadLimit(512)
// Configure Wait time for Pong response, use Current time + pongWait
// This has to be done here to set the first initial timer.
if err := c.connection.SetReadDeadline(time.Now().Add(pongWait)); err != nil {
log.Println(err)
return
}
// Configure how to handle Pong responses
c.connection.SetPongHandler(c.pongHandler)
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment