From 7c2b0dba33486aebe053790f04c1c58770e3586d Mon Sep 17 00:00:00 2001 From: Flandern1211 <3180066912wzw@gmail.com> Date: Sun, 12 Apr 2026 17:34:33 +0800 Subject: [PATCH 1/4] =?UTF-8?q?fix(user):=20=E4=BF=AE=E5=A4=8D=E5=AE=A2?= =?UTF-8?q?=E6=88=B7=E7=AB=AF=E4=BB=A3=E7=A0=81=E4=B8=AD=E7=9A=84=E6=B3=A8?= =?UTF-8?q?=E9=87=8A=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 clientWR.go 文件中添加了关于 bug 修复的注释说明 --- client/user/clientWR.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/client/user/clientWR.go b/client/user/clientWR.go index 63db4b5..c05571d 100644 --- a/client/user/clientWR.go +++ b/client/user/clientWR.go @@ -1,5 +1,7 @@ package user +//在代码里增添或修改一些bug + import ( "bufio" "encoding/binary" From 137c16c948709b5bfdc27507cc09599adfb2af3e Mon Sep 17 00:00:00 2001 From: Flandern1211 <3180066912wzw@gmail.com> Date: Mon, 13 Apr 2026 09:58:33 +0800 Subject: [PATCH 2/4] =?UTF-8?q?fix(user):=20=E4=BF=AE=E5=A4=8D=E5=AE=A2?= =?UTF-8?q?=E6=88=B7=E7=AB=AF=E4=BB=A3=E7=A0=81=E4=B8=AD=E7=9A=84=E6=B3=A8?= =?UTF-8?q?=E9=87=8A=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 clientWR.go 文件中添加了关于 bug 修复的注释说明 --- client/user/clientWR.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/user/clientWR.go b/client/user/clientWR.go index c05571d..716b728 100644 --- a/client/user/clientWR.go +++ b/client/user/clientWR.go @@ -1,6 +1,6 @@ package user -//在代码里增添或修改一些bug +//在代码里增或修改一些bug import ( "bufio" From 2626d445a32b1cf452315cd9e35124c08c0198d2 Mon Sep 17 00:00:00 2001 From: Flandern1211 <3180066912wzw@gmail.com> Date: Mon, 13 Apr 2026 11:16:17 +0800 Subject: [PATCH 3/4] =?UTF-8?q?fix(user):=20=E8=A7=A3=E5=86=B3=E6=B6=88?= =?UTF-8?q?=E6=81=AF=E5=86=99=E5=85=A5=E6=97=B6=E7=9A=84=E7=A9=BA=E5=86=85?= =?UTF-8?q?=E5=AE=B9=E6=A3=80=E6=9F=A5=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修改 writeMessage 函数返回实际写入字节数 - 添加对写入字节数为零的检查并返回错误 - 修复函数末尾错误返回值处理逻辑 --- client/user/clientWR.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/client/user/clientWR.go b/client/user/clientWR.go index 716b728..9e7266b 100644 --- a/client/user/clientWR.go +++ b/client/user/clientWR.go @@ -19,11 +19,14 @@ func writeMessage(conn net.Conn, msg string) error { } // 写入消息体 - _, err := conn.Write(msgBytes) + n, err := conn.Write(msgBytes) + if n == 0 { + return fmt.Errorf("消息内容为空") + } if err != nil { return fmt.Errorf("写入消息内容失败: %w", err) } - return nil + return fmt.Errorf("无错误") } func readMessage(conn net.Conn) (string, error) { reader := bufio.NewReader(conn) From 99f7ad5d68150b56832c6fd836c6ce379c0c786b Mon Sep 17 00:00:00 2001 From: Flandern1211 <3180066912wzw@gmail.com> Date: Mon, 13 Apr 2026 11:20:23 +0800 Subject: [PATCH 4/4] =?UTF-8?q?refactor(client):=20=E7=A7=BB=E9=99=A4?= =?UTF-8?q?=E6=9C=AA=E4=BD=BF=E7=94=A8=E7=9A=84=E5=AF=BC=E5=85=A5=E5=92=8C?= =?UTF-8?q?=E5=BA=9F=E5=BC=83=E7=9A=84readMessage=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 删除了未使用的 bufio 和 io 导入包 - 移除了不再调用的 readMessage 函数实现 - 简化了客户端代码结构 --- client/user/clientWR.go | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/client/user/clientWR.go b/client/user/clientWR.go index 9e7266b..6ef6cdb 100644 --- a/client/user/clientWR.go +++ b/client/user/clientWR.go @@ -3,10 +3,8 @@ package user //在代码里增或修改一些bug import ( - "bufio" "encoding/binary" "fmt" - "io" "net" ) @@ -28,25 +26,3 @@ func writeMessage(conn net.Conn, msg string) error { } return fmt.Errorf("无错误") } -func readMessage(conn net.Conn) (string, error) { - reader := bufio.NewReader(conn) - - // 读4字节长度 - lengthBytes := make([]byte, 4) - if _, err := io.ReadFull(reader, lengthBytes); err != nil { - return "", fmt.Errorf("读取消息长度失败: %w", err) - } - - msgLength := int(binary.BigEndian.Uint32(lengthBytes)) - if msgLength <= 0 { - return "", fmt.Errorf("非法消息长度: %d", msgLength) - } - - // 读取消息体 - msgBytes := make([]byte, msgLength) - if _, err := io.ReadFull(reader, msgBytes); err != nil { - return "", fmt.Errorf("读取消息内容失败: %w", err) - } - - return string(msgBytes), nil -}