- 修改 launch.json 中的端口设置,将 30000 改为 27777 - 在 ServerEvent.go 中添加 OnClose 方法,处理客户端断开连接的情况 - 在 main.go 中启用 CORS 支持 - 在 middleware.go 中注释掉 socket.ReadLoop 的调用
30 lines
674 B
Go
30 lines
674 B
Go
package main
|
|
|
|
import (
|
|
_ "github.com/gogf/gf/contrib/nosql/redis/v2"
|
|
"github.com/gogf/gf/v2/os/gcmd"
|
|
|
|
"blazing/common/socket"
|
|
"blazing/common/socket/handler"
|
|
"blazing/cool"
|
|
"blazing/logic/controller"
|
|
|
|
"github.com/gogf/gf/v2/os/gctx"
|
|
)
|
|
|
|
func main() {
|
|
// 解析命令行参数
|
|
cool.Config.PortBL = gcmd.GetOpt("port", "27000").String()
|
|
if cool.IsRedisMode {
|
|
go cool.ListenFunc(gctx.New())
|
|
}
|
|
|
|
Start(cool.Config.PortBL) //注入service
|
|
}
|
|
func Start(port string) {
|
|
|
|
head := handler.NewTomeeHandler()
|
|
head.Callback = controller.Recv
|
|
socket.NewServer(socket.WithPort(port), socket.WithCORS(), socket.WithSocketHandler(head)).Start()
|
|
}
|