From fdaddf9184a71a9e18f093b1ee3ad960af7fe3b4 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Wed, 26 Jul 2023 18:00:46 +0800 Subject: [PATCH] fix --- constants/websocket.go | 2 -- server/websocket/internal/logic/datatransferlogic.go | 4 ++-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/constants/websocket.go b/constants/websocket.go index 71f1fc36..93648380 100644 --- a/constants/websocket.go +++ b/constants/websocket.go @@ -8,8 +8,6 @@ const ( WEBSOCKET_UNAUTH = "WEBSOCKET_UNAUTH" //ws连接成功 WEBSOCKET_CONNECT_SUCCESS = "WEBSOCKET_CONNECT_SUCCESS" - //心跳信息 - WEBSOCKET_HEARTBEAT = "WEBSOCKET_HEARTBEAT" //图片渲染 WEBSOCKET_RENDER_IMAGE = "WEBSOCKET_RENDER_IMAGE" //数据格式错误 diff --git a/server/websocket/internal/logic/datatransferlogic.go b/server/websocket/internal/logic/datatransferlogic.go index 88097476..6c317518 100644 --- a/server/websocket/internal/logic/datatransferlogic.go +++ b/server/websocket/internal/logic/datatransferlogic.go @@ -142,12 +142,12 @@ func (l *DataTransferLogic) checkAuth(svcCtx *svc.ServiceContext, r *http.Reques // 心跳 func (w *wsConnectItem) heartbeat() { + tick := time.Tick(time.Second * 10) for { - time.Sleep(time.Second * 10) select { case <-w.closeChan: return - default: + case <-tick: //发送心跳信息 if err := w.conn.WriteMessage(websocket.PongMessage, nil); err != nil { logx.Error("发送心跳信息异常,关闭连接:", w.flag, err)