--- title: WebSocket menu: main: parent: recipes --- ## Server `server.go` ```go package main import ( "fmt" "github.com/labstack/echo" mw "github.com/labstack/echo/middleware" "golang.org/x/net/websocket" ) func main() { e := echo.New() e.Use(mw.Logger()) e.Use(mw.Recover()) e.Static("/", "public") e.WebSocket("/ws", func(c *echo.Context) (err error) { ws := c.Socket() msg := "" for { if err = websocket.Message.Send(ws, "Hello, Client!"); err != nil { return } if err = websocket.Message.Receive(ws, &msg); err != nil { return } fmt.Println(msg) } return }) e.Run(":1323") } ``` ## Client `index.html` ```html WebSocket

``` ## Output `Client` ```sh Hello, Client! Hello, Client! Hello, Client! Hello, Client! Hello, Client! ``` `Server` ```sh Hello, Server! Hello, Server! Hello, Server! Hello, Server! Hello, Server! ``` ## Maintainers - [vishr](http://github.com/vishr) ## [Source Code](https://github.com/labstack/echo/blob/master/recipes/websocket)