2015-06-10 00:24:01 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2015-07-13 00:41:46 +02:00
|
|
|
"fmt"
|
|
|
|
|
2015-06-10 05:06:51 +02:00
|
|
|
"github.com/labstack/echo"
|
2015-06-10 00:24:01 +02:00
|
|
|
mw "github.com/labstack/echo/middleware"
|
2015-07-03 07:55:00 +02:00
|
|
|
"golang.org/x/net/websocket"
|
2015-06-10 00:24:01 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
e := echo.New()
|
2015-07-02 20:14:09 +02:00
|
|
|
|
2015-06-10 00:24:01 +02:00
|
|
|
e.Use(mw.Logger())
|
2015-07-02 20:14:09 +02:00
|
|
|
e.Use(mw.Recover())
|
|
|
|
|
|
|
|
e.Static("/", "public")
|
2015-07-03 07:55:00 +02:00
|
|
|
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
|
|
|
|
}
|
2015-07-13 00:41:46 +02:00
|
|
|
fmt.Println(msg)
|
2015-07-03 07:55:00 +02:00
|
|
|
}
|
|
|
|
return
|
2015-06-10 00:24:01 +02:00
|
|
|
})
|
2015-07-02 20:14:09 +02:00
|
|
|
|
2015-06-10 00:24:01 +02:00
|
|
|
e.Run(":1323")
|
|
|
|
}
|