作者 crossoverJie

:bulb: Documenting source code.

@@ -17,7 +17,7 @@ public class CustomerHandleInitializer extends ChannelInitializer<Channel> { @@ -17,7 +17,7 @@ public class CustomerHandleInitializer extends ChannelInitializer<Channel> {
17 @Override 17 @Override
18 protected void initChannel(Channel ch) throws Exception { 18 protected void initChannel(Channel ch) throws Exception {
19 ch.pipeline() 19 ch.pipeline()
20 - //10 秒没发送消息 20 + //10 秒没发送消息 将IdleStateHandler 添加到 ChannelPipeline 中
21 .addLast(new IdleStateHandler(0, 10, 0)) 21 .addLast(new IdleStateHandler(0, 10, 0))
22 .addLast(new HeartbeatEncode()) 22 .addLast(new HeartbeatEncode())
23 .addLast(new EchoClientHandle()) 23 .addLast(new EchoClientHandle())
@@ -64,6 +64,7 @@ public class HeartBeatSimpleHandle extends SimpleChannelInboundHandler<CustomPro @@ -64,6 +64,7 @@ public class HeartBeatSimpleHandle extends SimpleChannelInboundHandler<CustomPro
64 protected void channelRead0(ChannelHandlerContext ctx, CustomProtocol customProtocol) throws Exception { 64 protected void channelRead0(ChannelHandlerContext ctx, CustomProtocol customProtocol) throws Exception {
65 LOGGER.info("收到customProtocol={}", customProtocol); 65 LOGGER.info("收到customProtocol={}", customProtocol);
66 66
  67 + //保存客户端与 Channel 之间的关系
67 NettySocketHolder.put(customProtocol.getId(),(NioSocketChannel)ctx.channel()) ; 68 NettySocketHolder.put(customProtocol.getId(),(NioSocketChannel)ctx.channel()) ;
68 } 69 }
69 } 70 }