func readLoop(s *glue.Socket) { for { // Wait for available data. // Optional: pass a timeout duration to read. data, err := s.Read() if err != nil { // Just return and release this goroutine if the socket was closed. if err == glue.ErrSocketClosed { return } log.Printf("read error: %v", err) continue } // Echo the received data back to the client. s.Write(data) } }