关于Netty 设置读写超时不起作用没有触发以及ChannelPipeline和IdleStateHandler的坑

添加IdleStateHandler的超时Handler时发现超时并没有触发userEventTriggered();

解决办法:
把IdleStateHandler放在pipeline的最上面

//netty pipeline顺序有讲究
ChannelPipeline pipeline = ch.pipeline();
pipeline.addLast(new IdleStateHandler(20,20,25,TimeUnit.SECONDS));
pipeline.addLast(new StringDecoder(Charset.forName("UTF-8")));
pipeline.addLast(new ClientPoHandlerProto(mHandler));
pipeline.addLast(new StringEncoder(Charset.forName("GBK")));

你可能感兴趣的:(Android开发)