正在显示
2 个修改的文件
包含
2 行增加
和
1 行删除
| @@ -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()) |
netty-action-heartbeat/src/main/java/com/crossoverjie/netty/action/handle/HeartBeatSimpleHandle.java
| @@ -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 | } |
-
请 注册 或 登录 后发表评论