From 3634fe2ab8f51773872e7b43bed307629c84cee1 Mon Sep 17 00:00:00 2001 From: zhuyijun Date: Mon, 18 Oct 2021 19:09:43 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0protocol?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../netty/protocoltcp/MyClientHandler.java | 5 ++++- .../netty/protocoltcp/MyClientInitializer.java | 3 +++ .../netty/protocoltcp/MyMessageDecoder.java | 2 +- .../netty/protocoltcp/MyMessageEncoder.java | 2 +- .../netty/protocoltcp/MyServerHandler.java | 13 ++++++++++++- .../netty/protocoltcp/MyServerInitializer.java | 3 +++ .../cn/zyjblogs/netty/source/echo/EchoClient.java | 14 ++------------ .../netty/source/echo/EchoClientHandler.java | 2 -- .../cn/zyjblogs/netty/source/echo/EchoServer.java | 6 +----- 9 files changed, 27 insertions(+), 23 deletions(-) diff --git a/nettyPro/src/main/java/cn/zyjblogs/netty/protocoltcp/MyClientHandler.java b/nettyPro/src/main/java/cn/zyjblogs/netty/protocoltcp/MyClientHandler.java index 74d7cf2..70aa2f8 100644 --- a/nettyPro/src/main/java/cn/zyjblogs/netty/protocoltcp/MyClientHandler.java +++ b/nettyPro/src/main/java/cn/zyjblogs/netty/protocoltcp/MyClientHandler.java @@ -19,7 +19,10 @@ public class MyClientHandler extends SimpleChannelInboundHandler { @Override protected void encode(ChannelHandlerContext ctx, MessageProtocol msg, ByteBuf out) throws Exception { - System.out.println("MyMessageEncoder方法被调用 编码"); + System.out.println("\nMyMessageEncoder方法被调用 编码"); out.writeInt(msg.getLen()); out.writeBytes(msg.getContent()); } diff --git a/nettyPro/src/main/java/cn/zyjblogs/netty/protocoltcp/MyServerHandler.java b/nettyPro/src/main/java/cn/zyjblogs/netty/protocoltcp/MyServerHandler.java index c34b4fd..6b262db 100644 --- a/nettyPro/src/main/java/cn/zyjblogs/netty/protocoltcp/MyServerHandler.java +++ b/nettyPro/src/main/java/cn/zyjblogs/netty/protocoltcp/MyServerHandler.java @@ -7,6 +7,7 @@ import io.netty.channel.ChannelHandlerContext; import io.netty.channel.SimpleChannelInboundHandler; import io.netty.util.CharsetUtil; +import java.nio.charset.StandardCharsets; import java.util.UUID; public class MyServerHandler extends SimpleChannelInboundHandler { @@ -20,9 +21,19 @@ public class MyServerHandler extends SimpleChannelInboundHandler