diff --git a/src/main/java/org/netty/demo/protocol/CmdHandlerInitializer.java b/src/main/java/org/netty/demo/protocol/CmdHandlerInitializer.java index fae5987..5dc7726 100644 --- a/src/main/java/org/netty/demo/protocol/CmdHandlerInitializer.java +++ b/src/main/java/org/netty/demo/protocol/CmdHandlerInitializer.java @@ -8,7 +8,9 @@ import io.netty.handler.codec.LineBasedFrameDecoder; /** - * Created by XiuYin.Cui on 2018/8/26. + * 传入数据流是一系列的帧,每个帧都由换行符(\n)分隔; + * 每个帧都由一系列的元素组成,每个元素都由单个空格字符分隔; + * 一个帧的内容代表一个命令,定义为一个命令名称后跟着数目可变的参数。 */ public class CmdHandlerInitializer extends ChannelInitializer { @@ -25,7 +27,9 @@ protected void initChannel(Channel ch) throws Exception { * Cmd POJO */ public static final class Cmd { + // 表示命令 private final ByteBuf name; + //表示可变的参数 private final ByteBuf args; public Cmd(ByteBuf name, ByteBuf args) { diff --git a/src/main/java/org/netty/demo/protocol/LengthBasedInitializer.java b/src/main/java/org/netty/demo/protocol/LengthBasedInitializer.java index 59c97d8..ff08d70 100644 --- a/src/main/java/org/netty/demo/protocol/LengthBasedInitializer.java +++ b/src/main/java/org/netty/demo/protocol/LengthBasedInitializer.java @@ -12,7 +12,6 @@ */ public class LengthBasedInitializer extends ChannelInitializer { - @Override protected void initChannel(Channel ch) throws Exception { ch.pipeline().addLast( diff --git a/src/main/java/org/netty/demo/protocol/LineBasedHandlerInitializer.java b/src/main/java/org/netty/demo/protocol/LineBasedHandlerInitializer.java index 3c6812b..179d405 100644 --- a/src/main/java/org/netty/demo/protocol/LineBasedHandlerInitializer.java +++ b/src/main/java/org/netty/demo/protocol/LineBasedHandlerInitializer.java @@ -17,11 +17,11 @@ protected void initChannel(Channel ch) throws Exception { ch.pipeline().addLast( // 将提取到的桢转发给下一个Channelhandler new LineBasedFrameDecoder(64 * 1024), + // 添加 FrameHandler 以接收帧 new FrameHandler() ); } - public static final class FrameHandler extends SimpleChannelInboundHandler { @Override