提交
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user