Skip to content

Commit

Permalink
Add MsgId to WebSocket communication
Browse files Browse the repository at this point in the history
  • Loading branch information
golangboy committed Feb 28, 2024
1 parent 7518393 commit 6113889
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 2 additions & 1 deletion client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 {
Expand Down

0 comments on commit 6113889

Please sign in to comment.