O'Reilly logo

Isomorphic Go by Kamesh Balasubramanian

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The client type

The Client type acts as a broker between  Hub and the websocket connection.

Here's what the Client struct looks like:

type Client struct {  hub *Hub  conn *websocket.Conn  send chan []byte}

Each Client value contains a pointer to Hub, a pointer to a websocket connection, and a buffered channel, send, meant for outbound messages.

The readPump method is responsible for relaying inbound messages coming in over the websocket connection to the hub:

func (c *Client) readPump() {  defer func() {    c.hub.unregister <- c    c.conn.Close()  }()  c.conn.SetReadLimit(maxMessageSize)  c.conn.SetReadDeadline(time.Now().Add(pongWait))  c.conn.SetPongHandler(func(string) error { c.conn.SetReadDeadline(time.Now().Add(pongWait)); return nil })  for { _, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required