feat(socket): 实现 WebSocket 代理功能

- 新增 WebSocket 中间件,支持连接到指定端口的 TCP 服务器
- 在 ServerEvent 中添加错误日志输出
- 优化 ClientData 解析逻辑,增加类型断言
- 更新 index.html,添加 socket 代理配置
This commit is contained in:
2025-07-10 01:01:43 +08:00
parent c76c2f4139
commit cd2a5db9d2
5 changed files with 111 additions and 6 deletions

View File

@@ -22,6 +22,7 @@ func (s *Server) Boot() error {
return err
}
// err := gnet.Run(s, s.network+"://"+s.addr, gnet.WithMulticore(s.multicore))
glog.Debug(context.Background(), "server exits with error: %v", err)
// logging.Infof("server exits with error: %v", err)
return nil
}
@@ -36,7 +37,11 @@ func (s *Server) Stop() error {
func (s *Server) OnClose(c gnet.Conn, _ error) (action gnet.Action) {
atomic.AddInt64(&s.connected, -1)
//logging.Infof("conn[%v] disconnected", c.RemoteAddr().String())
v := c.Context().(*entity.ClientData)
v, ok := c.Context().(*entity.ClientData)
if !ok {
return
}
t := v.GetPlayer()
if t != nil {
glog.Debug(context.Background(), t.UserID, "断开连接")