mirror of
https://gitee.com/johng/gf.git
synced 2024-12-05 05:37:55 +08:00
32 lines
537 B
Go
32 lines
537 B
Go
package main
|
|
|
|
import (
|
|
"github.com/gogf/gf/frame/g"
|
|
"github.com/gogf/gf/net/ghttp"
|
|
"github.com/gogf/gf/os/gfile"
|
|
"github.com/gogf/gf/os/glog"
|
|
)
|
|
|
|
func main() {
|
|
s := g.Server()
|
|
s.BindHandler("/ws", func(r *ghttp.Request) {
|
|
ws, err := r.WebSocket()
|
|
if err != nil {
|
|
glog.Error(err)
|
|
r.Exit()
|
|
}
|
|
for {
|
|
msgType, msg, err := ws.ReadMessage()
|
|
if err != nil {
|
|
return
|
|
}
|
|
if err = ws.WriteMessage(msgType, msg); err != nil {
|
|
return
|
|
}
|
|
}
|
|
})
|
|
s.SetServerRoot(gfile.MainPkgPath())
|
|
s.SetPort(8199)
|
|
s.Run()
|
|
}
|