|
|
@@ -59,9 +59,19 @@ func (c *Client) read() {
|
|
|
_, msg, err := c.socket.ReadMessage()
|
|
|
// break if there is an error
|
|
|
if err != nil {
|
|
|
+ log.Error().Err(err).Str("client", c.name).Msg("读取WebSocket消息失败")
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+ // 记录原始消息内容用于调试
|
|
|
+ //log.Debug().Str("client", c.name).Int("rawMessageLength", len(msg)).Str("rawMessage", string(msg)).Msg("读取到原始WebSocket消息")
|
|
|
+
|
|
|
+ // 在此处处理心跳消息
|
|
|
+ if string(msg) == "*hb*" {
|
|
|
+ log.Debug().Str("client", c.name).Str("message", string(msg)).Msg("Received heartbeat message")
|
|
|
+ continue
|
|
|
+ }
|
|
|
+
|
|
|
// 构造要发送的消息对象,包含用户名和消息内容
|
|
|
outgoing := map[string]string{
|
|
|
"name": c.name, // 发送者用户名
|