From 265fd81b279be63f326c7b5e1d4e7785718f0c99 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Wed, 26 Jul 2023 18:03:27 +0800 Subject: [PATCH] fix --- server/websocket/internal/logic/datatransferlogic.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/server/websocket/internal/logic/datatransferlogic.go b/server/websocket/internal/logic/datatransferlogic.go index 6c317518..b0961617 100644 --- a/server/websocket/internal/logic/datatransferlogic.go +++ b/server/websocket/internal/logic/datatransferlogic.go @@ -106,7 +106,7 @@ func (l *DataTransferLogic) DataTransfer(svcCtx *svc.ServiceContext, w http.Resp rsp.T = constants.WEBSOCKET_CONNECT_SUCCESS rsp.D = flag b, _ := json.Marshal(rsp) - conn.WriteMessage(websocket.TextMessage, b) + _ = conn.WriteMessage(websocket.TextMessage, b) //循环读客户端信息 go ws.readLoop() //循环把数据发送给客户端 @@ -181,7 +181,11 @@ func (w *wsConnectItem) writeLoop() { case <-w.closeChan: //如果关闭了 return case data := <-w.outChan: - w.conn.WriteMessage(websocket.TextMessage, data) + if err := w.conn.WriteMessage(websocket.TextMessage, data); err != nil { + logx.Error("websocket write loop err:", err) + w.close() + return + } } } }