diff --git a/examples/echo/client.go b/examples/echo/client.go index d53b81c8..8296e2c4 100644 --- a/examples/echo/client.go +++ b/examples/echo/client.go @@ -41,12 +41,16 @@ func main() { go func() { defer close(done) for { - mt, message, err := c.ReadMessage() + messageType, message, err := c.ReadMessage() if err != nil { log.Println("read:", err) return } - log.Printf("recv: %s, type: %s", message, websocket.FormatMessageType(mt)) + if messageType == websocket.TextMessage { + log.Printf("received text message: %s", message) + } else if messageType == websocket.BinaryMessage { + log.Printf("received binary message: %s", message) + } } }() @@ -68,7 +72,10 @@ func main() { // Cleanly close the connection by sending a close message and then // waiting (with timeout) for the server to close the connection. - err := c.WriteMessage(websocket.CloseMessage, websocket.FormatCloseMessage(websocket.CloseNormalClosure, "")) + err := c.WriteMessage( + websocket.CloseMessage, + websocket.FormatCloseMessage(websocket.CloseNormalClosure, ""), + ) if err != nil { log.Println("write close:", err) return diff --git a/examples/echo/server.go b/examples/echo/server.go index 9804e6b2..7cee8f94 100644 --- a/examples/echo/server.go +++ b/examples/echo/server.go @@ -28,14 +28,18 @@ func echo(w http.ResponseWriter, r *http.Request) { } defer c.Close() for { - mt, message, err := c.ReadMessage() + messageType, message, err := c.ReadMessage() if err != nil { log.Println("read:", err) break } - log.Printf("recv: %s, type: %s", message, websocket.FormatMessageType(mt)) - err = c.WriteMessage(mt, message) + if messageType == websocket.TextMessage { + log.Printf("received text message: %s", message) + } else if messageType == websocket.BinaryMessage { + log.Printf("received binary message: %s", message) + } + err = c.WriteMessage(messageType, message) if err != nil { log.Println("write:", err) break @@ -60,7 +64,7 @@ var homeTemplate = template.Must(template.New("").Parse(`
-