We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
func (c *Client) Read() { go func() { defer func() { // 当 goroutine 退出时触发断开连接 Manager.DisConnect <- c }()
for { messageType, _, err := c.Socket.ReadMessage() if err != nil { // 检查是否是 WebSocket 连接正常关闭的错误 if websocket.IsCloseError(err, websocket.CloseGoingAway, websocket.CloseNormalClosure, websocket.CloseNoStatusReceived) { return } // 其他错误或网络问题也应该退出读取循环 return } // 您可以根据需要处理不同类型的消息 if messageType == websocket.PingMessage { // 对 Ping 消息做出反应,例如发送 Pong 消息 _ = c.Socket.WriteMessage(websocket.PongMessage, nil) } } }()
}
The text was updated successfully, but these errors were encountered:
No branches or pull requests
func (c *Client) Read() {
go func() {
defer func() {
// 当 goroutine 退出时触发断开连接
Manager.DisConnect <- c
}()
}
The text was updated successfully, but these errors were encountered: