正在显示
2 个修改的文件
包含
3 行增加
和
2 行删除
| @@ -4,6 +4,7 @@ import com.crossoverjie.netty.action.client.util.SpringBeanFactory; | @@ -4,6 +4,7 @@ import com.crossoverjie.netty.action.client.util.SpringBeanFactory; | ||
| 4 | import com.crossoverjie.netty.action.common.pojo.CustomProtocol; | 4 | import com.crossoverjie.netty.action.common.pojo.CustomProtocol; |
| 5 | import io.netty.buffer.ByteBuf; | 5 | import io.netty.buffer.ByteBuf; |
| 6 | import io.netty.buffer.Unpooled; | 6 | import io.netty.buffer.Unpooled; |
| 7 | +import io.netty.channel.ChannelFutureListener; | ||
| 7 | import io.netty.channel.ChannelHandlerContext; | 8 | import io.netty.channel.ChannelHandlerContext; |
| 8 | import io.netty.channel.SimpleChannelInboundHandler; | 9 | import io.netty.channel.SimpleChannelInboundHandler; |
| 9 | import io.netty.handler.timeout.IdleState; | 10 | import io.netty.handler.timeout.IdleState; |
| @@ -35,7 +36,7 @@ public class EchoClientHandle extends SimpleChannelInboundHandler<ByteBuf> { | @@ -35,7 +36,7 @@ public class EchoClientHandle extends SimpleChannelInboundHandler<ByteBuf> { | ||
| 35 | LOGGER.info("已经 10 秒没有发送信息!"); | 36 | LOGGER.info("已经 10 秒没有发送信息!"); |
| 36 | //向服务端发送消息 | 37 | //向服务端发送消息 |
| 37 | CustomProtocol heartBeat = SpringBeanFactory.getBean("heartBeat", CustomProtocol.class); | 38 | CustomProtocol heartBeat = SpringBeanFactory.getBean("heartBeat", CustomProtocol.class); |
| 38 | - ctx.writeAndFlush(heartBeat) ; | 39 | + ctx.writeAndFlush(heartBeat).addListener(ChannelFutureListener.CLOSE_ON_FAILURE) ; |
| 39 | } | 40 | } |
| 40 | 41 | ||
| 41 | 42 |
netty-action-heartbeat/src/main/java/com/crossoverjie/netty/action/handle/HeartBeatSimpleHandle.java
| @@ -51,7 +51,7 @@ public class HeartBeatSimpleHandle extends SimpleChannelInboundHandler<CustomPro | @@ -51,7 +51,7 @@ public class HeartBeatSimpleHandle extends SimpleChannelInboundHandler<CustomPro | ||
| 51 | if (idleStateEvent.state() == IdleState.READER_IDLE){ | 51 | if (idleStateEvent.state() == IdleState.READER_IDLE){ |
| 52 | LOGGER.info("已经5秒没有收到信息!"); | 52 | LOGGER.info("已经5秒没有收到信息!"); |
| 53 | //向客户端发送消息 | 53 | //向客户端发送消息 |
| 54 | - ctx.writeAndFlush(HEART_BEAT) ; | 54 | + ctx.writeAndFlush(HEART_BEAT).addListener(ChannelFutureListener.CLOSE_ON_FAILURE) ; |
| 55 | } | 55 | } |
| 56 | 56 | ||
| 57 | 57 |
-
请 注册 或 登录 后发表评论