This commit is contained in:
cdf
2025-01-16 19:32:46 +08:00
parent bdc3df38a3
commit 12e805ccc1
3 changed files with 5 additions and 5 deletions

View File

@@ -47,7 +47,7 @@ public class NettyClient {
//空闲状态的handler
// 添加LineBasedFrameDecoder来按行分割数据
.addLast(new LineBasedFrameDecoder(10240))
.addLast(new IdleStateHandler(10, 0, 0, TimeUnit.SECONDS))
.addLast(new IdleStateHandler(0, 10, 0, TimeUnit.SECONDS))
.addLast(new StringDecoder(CharsetUtil.UTF_8))
.addLast(new StringEncoder(CharsetUtil.UTF_8))
.addLast(handler);

View File

@@ -93,7 +93,7 @@ public class NettySourceClientHandler extends SimpleChannelInboundHandler<String
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) {
//如果是空闲状态事件
if (evt instanceof IdleStateEvent) {
if (((IdleStateEvent) evt).state() == IdleState.READER_IDLE) {
if (((IdleStateEvent) evt).state() == IdleState.WRITER_IDLE) {
//发送ping 保持心跳链接
SocketMsg msg = new SocketMsg();
msg.setRequestId("yxt");