Compare commits

..

2 Commits

Author SHA1 Message Date
wuko233 6c6995d2dd fix: 修复网络连接时波动导致客户端死锁问题 2026-02-17 09:56:07 +08:00
wuko233 8ae1b59a55 chore: 更新.gitignore,添加测试文件夹test/ 2026-02-17 09:23:44 +08:00
2 changed files with 16 additions and 5 deletions

3
.gitignore vendored
View File

@ -37,3 +37,6 @@ config.local.yaml
# 需求文件
todo.txt
# 测试文件
test/

View File

@ -118,14 +118,22 @@ func (c *WSClient) closeConn() {
c.isConnected = false
}
func (c *WSClient) connect() any {
c.mu.Lock()
defer c.mu.Unlock()
func (c *WSClient) connect() error {
conn, _, err := websocket.DefaultDialer.Dial(c.config.ServerURL, nil)
if err != nil {
return err
}
c.mu.Lock()
defer c.mu.Unlock()
select {
case <-c.stopChan:
conn.Close()
return nil
default:
}
c.conn = conn
c.isConnected = true
log.Printf("[网络] 成功连接到服务器: %s", c.config.ServerURL)