serveWs handles websocket requests from the peer.
(hub *Hub, w http.ResponseWriter, r *http.Request)
| 122 | |
| 123 | // serveWs handles websocket requests from the peer. |
| 124 | func serveWs(hub *Hub, w http.ResponseWriter, r *http.Request) { |
| 125 | conn, err := upgrader.Upgrade(w, r, nil) |
| 126 | if err != nil { |
| 127 | log.Println(err) |
| 128 | return |
| 129 | } |
| 130 | client := &Client{hub: hub, conn: conn, send: make(chan []byte, 256)} |
| 131 | client.hub.register <- client |
| 132 | |
| 133 | // Allow collection of memory referenced by the caller by doing all work in |
| 134 | // new goroutines. |
| 135 | go client.writePump() |
| 136 | go client.readPump() |
| 137 | } |