This commit is contained in:
laodaming 2023-07-26 19:29:23 +08:00
parent f609fa364d
commit 72543d519f

View File

@ -142,14 +142,12 @@ func (l *DataTransferLogic) checkAuth(svcCtx *svc.ServiceContext, r *http.Reques
// 心跳
func (w *wsConnectItem) heartbeat() {
tick := time.Tick(time.Second * 2)
tick := time.Tick(time.Second * 10)
for {
select {
case <-w.closeChan:
return
case <-tick:
//设置写超时时间10s
_ = w.conn.SetWriteDeadline(time.Now().Add(time.Second * 10))
//发送心跳信息
if err := w.conn.WriteMessage(websocket.PongMessage, nil); err != nil {
logx.Error("发送心跳信息异常,关闭连接:", w.flag, err)
@ -166,7 +164,6 @@ func (w *wsConnectItem) close() {
defer w.mutex.Unlock()
logx.Info("websocket:", w.flag, " is closing...")
//发送关闭信息
_ = w.conn.SetWriteDeadline(time.Now().Add(time.Second))
_ = w.conn.WriteMessage(websocket.CloseMessage, nil)
w.conn.Close()
mapConnPool.Delete(w.flag)