From 61138897115c16a796cf5bb11f4a4fd8a0c356a7 Mon Sep 17 00:00:00 2001 From: golangboy Date: Thu, 29 Feb 2024 00:38:00 +0800 Subject: [PATCH] Add MsgId to WebSocket communication --- client/main.go | 3 ++- server/main.go | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/client/main.go b/client/main.go index 5d4650c..77faff5 100644 --- a/client/main.go +++ b/client/main.go @@ -214,7 +214,7 @@ func handleConnection(clientConn net.Conn) { clientConn.Write([]byte("HTTP/1.1 200 Connection Established\r\n\r\n")) } if false == isSocks5 && false == isHttps { - err = ws.Conn.WriteJSON(common.Proto{MsgType: common.ReqData, Data: buf[:nbytes]}) + err = ws.Conn.WriteJSON(common.Proto{MsgType: common.ReqData, Data: buf[:nbytes], MsgId: msgId}) if err != nil { log.Printf("[%s]Failed to send http data to WebSocket server: %v", msgId, err) } @@ -245,6 +245,7 @@ func handleConnection(clientConn net.Conn) { err = ws.Conn.WriteJSON(common.Proto{ MsgType: common.ReqData, Data: buf[:n], + MsgId: msgId, }) ws.Unlock() if err != nil { diff --git a/server/main.go b/server/main.go index 3dc29f7..ce27eac 100644 --- a/server/main.go +++ b/server/main.go @@ -42,6 +42,7 @@ func main() { } err = ws.Conn.WriteJSON(common.Proto{ MsgType: common.ReqConnect, + MsgId: msgId, }) if err != nil { log.Printf("[%s]Failed to send connection success message to the client: %v", msgId, err) @@ -59,6 +60,7 @@ func main() { err = ws.Conn.WriteJSON(common.Proto{ MsgType: common.ReqData, Data: buf[:n], + MsgId: msgId, }) ws.Unlock() if err != nil {