1
0
mirror of https://github.com/labstack/echo.git synced 2025-01-12 01:22:21 +02:00
echo/recipes/websocket/server.go
Chase Hutchins 959f4bd1ab Updated websocket recipe
Signed-off-by: Vishal Rana <vr@labstack.com>
2015-07-12 21:49:21 -07:00

36 lines
550 B
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")
}