客户端每5秒发送一次心跳给服务端,服务端记录最后一次心跳时间,通过定时任务每10秒检测一下,如果当前时间与最后一次收到的心跳时间之差超过某个阈值,断开与客户端的连接。基于之前的例子(netty5心跳与业务消息分发实例),我们修改下服务端的心跳handler(HeartBeatServerHandler):
package com.wlf.netty.nettyserver.handler; import com.wlf.netty.nettyapi.constant.MessageType; import com.wlf.netty.nettyapi.javabean.NettyMessage; import io.netty.channel.ChannelHandlerAdapter; import io.netty.channel.ChannelHandlerContext; import io.netty.util.concurrent.ScheduledFuture; import lombok.extern.slf4j.Slf4j; import java.util.concurrent.TimeUnit; @Slf4j public class HeartBeatServerHandler extends ChannelHandlerAdapter { private volatile boolean isReceiveHeart = false; private volatile int interval = 10000; private volatile ScheduledFuture<?> heartBeatLost; // 心跳消息接收时间点 private final ThreadLocal<Long> heartBeatTime = new ThreadLocal<>(); @Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { NettyMessage nettyMessage = (NettyMessage) msg; // 接收到心跳请求,打印心跳消息 if (nettyMessage.getHeader() != null && nettyMessage.getHeader().getType() == MessageType.HEART_TYPE.getType()) { // 收到消息 isReceiveHeart = true; // 获取最后一次心跳收到的时间 heartBeatTime.set(System.currentTimeMillis()); log.info("[server] Receive client heart beat message : ----> {}", nettyMessage); } else { ctx.fireChannelRead(msg); } } @Override public void channelActive(ChannelHandlerContext ctx) throws Exception { // 通道联通后开始定时监听连接接入,超时则断连 heartBeatLost = ctx.executor().scheduleAtFixedRate(new Runnable() { @Override public void run() { log.info("isReceiveHeart : {}", isReceiveHeart); if (isReceiveHeart) { long currentTime = System.currentTimeMillis(); long lastHeartBeatTime = heartBeatTime.get() == null ? currentTime : heartBeatTime.get(); long timeOut = currentTime - lastHeartBeatTime; log.info("[server] heart timeOut is : {} ms", timeOut); if (timeOut > interval) { log.error("[server] heart beat time out."); // 关闭监听任务,断开通道 heartBeatLost.cancel(true); ctx.close(); } } } }, 0, interval, TimeUnit.MILLISECONDS); } /** * 在处理过程中引发异常时被调用 * * @param ctx * @param cause * @throws Exception */ @Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { log.error("[server] heart response error: {}", cause.getMessage()); if (heartBeatLost != null) { heartBeatLost.cancel(true); heartBeatLost = null; } ctx.fireExceptionCaught(cause); } }
当通道激活时我们起一个定时任务检测,若有心跳消息进来,我们开始计算心跳是否超时,当客户端把文件发完后,心跳也不跳了,服务端检测到超时断连,客户端输出结果:
16:42:52.724 [nioEventLoopGroup-1-0] INFO com.wlf.netty.nettyclient.handler.HeartBeatClientHandler - [client] control response is OK, header : Header{delimiter=-1410399999, length=8, type=0, reserved=0}. sid : 86, interval : 5000 16:42:57.767 [nioEventLoopGroup-1-0] INFO com.wlf.netty.nettyclient.handler.HeartBeatClientHandler - [client] Client send heart beat message to server : ----> NettyMessage{header=Header{delimiter=-1410399999, length=4, type=3, reserved=0}, data=[B@26588df6} 16:42:57.767 [nioEventLoopGroup-1-0] INFO com.wlf.netty.nettyclient.handler.HeartBeatClientHandler - [client] Client send business message to server : ----> NettyMessage{header=Header{delimiter=-1410399999, length=161800, type=1, reserved=0}, data=[B@3824d9ae} 16:43:02.776 [nioEventLoopGroup-1-0] INFO com.wlf.netty.nettyclient.handler.HeartBeatClientHandler - [client] Client send heart beat message to server : ----> NettyMessage{header=Header{delimiter=-1410399999, length=4, type=3, reserved=0}, data=[B@5d32661a} 16:43:02.776 [nioEventLoopGroup-1-0] INFO com.wlf.netty.nettyclient.handler.HeartBeatClientHandler - [client] Client send business message to server : ----> NettyMessage{header=Header{delimiter=-1410399999, length=161800, type=1, reserved=0}, data=[B@10753be4} 16:43:07.813 [nioEventLoopGroup-1-0] INFO com.wlf.netty.nettyclient.handler.HeartBeatClientHandler - [client] Client send heart beat message to server : ----> NettyMessage{header=Header{delimiter=-1410399999, length=4, type=3, reserved=0}, data=[B@72a02321} 16:43:07.813 [nioEventLoopGroup-1-0] INFO com.wlf.netty.nettyclient.handler.HeartBeatClientHandler - [client] Client send business message to server : ----> NettyMessage{header=Header{delimiter=-1410399999, length=161800, type=1, reserved=0}, data=[B@6c576d72} 16:43:12.839 [nioEventLoopGroup-1-0] INFO com.wlf.netty.nettyclient.handler.HeartBeatClientHandler - [client] Client send heart beat message to server : ----> NettyMessage{header=Header{delimiter=-1410399999, length=4, type=3, reserved=0}, data=[B@221bd454} 16:43:12.839 [nioEventLoopGroup-1-0] INFO com.wlf.netty.nettyclient.handler.HeartBeatClientHandler - [client] Client send business message to server : ----> NettyMessage{header=Header{delimiter=-1410399999, length=161800, type=1, reserved=0}, data=[B@1b8861e8} 16:43:17.863 [nioEventLoopGroup-1-0] INFO com.wlf.netty.nettyclient.handler.HeartBeatClientHandler - [client] Client send heart beat message to server : ----> NettyMessage{header=Header{delimiter=-1410399999, length=4, type=3, reserved=0}, data=[B@6842f093} 16:43:17.863 [nioEventLoopGroup-1-0] INFO com.wlf.netty.nettyclient.handler.HeartBeatClientHandler - [client] Client send business message to server : ----> NettyMessage{header=Header{delimiter=-1410399999, length=161800, type=1, reserved=0}, data=[B@3fa93c14} 16:43:22.884 [nioEventLoopGroup-1-0] INFO com.wlf.netty.nettyclient.handler.HeartBeatClientHandler - [client] Client send heart beat message to server : ----> NettyMessage{header=Header{delimiter=-1410399999, length=4, type=3, reserved=0}, data=[B@43ece6c1} 16:43:22.884 [nioEventLoopGroup-1-0] INFO com.wlf.netty.nettyclient.handler.HeartBeatClientHandler - [client] Client send business message to server : ----> NettyMessage{header=Header{delimiter=-1410399999, length=161800, type=1, reserved=0}, data=[B@1b334875} 16:43:27.893 [nioEventLoopGroup-1-0] INFO com.wlf.netty.nettyclient.handler.HeartBeatClientHandler - [client] Client send heart beat message to server : ----> NettyMessage{header=Header{delimiter=-1410399999, length=4, type=3, reserved=0}, data=[B@648ae5e8} 16:43:27.893 [nioEventLoopGroup-1-0] INFO com.wlf.netty.nettyclient.handler.HeartBeatClientHandler - [client] Client send business message to server : ----> NettyMessage{header=Header{delimiter=-1410399999, length=161800, type=1, reserved=0}, data=[B@12353cf1} 16:43:32.935 [nioEventLoopGroup-1-0] INFO com.wlf.netty.nettyclient.handler.HeartBeatClientHandler - [client] Client send heart beat message to server : ----> NettyMessage{header=Header{delimiter=-1410399999, length=4, type=3, reserved=0}, data=[B@36cb1a98} 16:43:32.935 [nioEventLoopGroup-1-0] INFO com.wlf.netty.nettyclient.handler.HeartBeatClientHandler - [client] Client send business message to server : ----> NettyMessage{header=Header{delimiter=-1410399999, length=161800, type=1, reserved=0}, data=[B@373a9cd4} 16:43:37.943 [nioEventLoopGroup-1-0] INFO com.wlf.netty.nettyclient.handler.HeartBeatClientHandler - [client] Client send heart beat message to server : ----> NettyMessage{header=Header{delimiter=-1410399999, length=4, type=3, reserved=0}, data=[B@4ac9a7e} 16:43:37.943 [nioEventLoopGroup-1-0] INFO com.wlf.netty.nettyclient.handler.HeartBeatClientHandler - [client] Client send business message to server : ----> NettyMessage{header=Header{delimiter=-1410399999, length=161800, type=1, reserved=0}, data=[B@3f45fcae} 16:43:42.951 [nioEventLoopGroup-1-0] INFO com.wlf.netty.nettyclient.handler.HeartBeatClientHandler - [client] Client send heart beat message to server : ----> NettyMessage{header=Header{delimiter=-1410399999, length=4, type=3, reserved=0}, data=[B@51b43e04} 16:43:42.951 [nioEventLoopGroup-1-0] INFO com.wlf.netty.nettyclient.handler.HeartBeatClientHandler - [client] Client send business message to server : ----> NettyMessage{header=Header{delimiter=-1410399999, length=161800, type=1, reserved=0}, data=[B@328bc4da} 16:43:47.967 [nioEventLoopGroup-1-0] INFO com.wlf.netty.nettyclient.handler.HeartBeatClientHandler - [client] Client send heart beat message to server : ----> NettyMessage{header=Header{delimiter=-1410399999, length=4, type=3, reserved=0}, data=[B@5294d79f} 16:43:47.967 [nioEventLoopGroup-1-0] INFO com.wlf.netty.nettyclient.handler.HeartBeatClientHandler - [client] Client send business message to server : ----> NettyMessage{header=Header{delimiter=-1410399999, length=161800, type=1, reserved=0}, data=[B@4224f1ef} 16:43:52.974 [nioEventLoopGroup-1-0] INFO com.wlf.netty.nettyclient.handler.HeartBeatClientHandler - [client] Client send heart beat message to server : ----> NettyMessage{header=Header{delimiter=-1410399999, length=4, type=3, reserved=0}, data=[B@3210a3b1} 16:43:52.974 [nioEventLoopGroup-1-0] INFO com.wlf.netty.nettyclient.handler.HeartBeatClientHandler - [client] Client send business message to server : ----> NettyMessage{header=Header{delimiter=-1410399999, length=161800, type=1, reserved=0}, data=[B@5ed11c3d} 16:43:58.012 [nioEventLoopGroup-1-0] INFO com.wlf.netty.nettyclient.handler.HeartBeatClientHandler - [client] Client send heart beat message to server : ----> NettyMessage{header=Header{delimiter=-1410399999, length=4, type=3, reserved=0}, data=[B@2a0d1057} 16:43:58.012 [nioEventLoopGroup-1-0] INFO com.wlf.netty.nettyclient.handler.HeartBeatClientHandler - [client] Client send business message to server : ----> NettyMessage{header=Header{delimiter=-1410399999, length=161800, type=1, reserved=0}, data=[B@4fc32770} 16:44:03.020 [nioEventLoopGroup-1-0] INFO com.wlf.netty.nettyclient.handler.HeartBeatClientHandler - [client] Client send heart beat message to server : ----> NettyMessage{header=Header{delimiter=-1410399999, length=4, type=3, reserved=0}, data=[B@78791812} 16:44:03.020 [nioEventLoopGroup-1-0] INFO com.wlf.netty.nettyclient.handler.HeartBeatClientHandler - [client] Client send business message to server : ----> NettyMessage{header=Header{delimiter=-1410399999, length=161800, type=1, reserved=0}, data=[B@2e9fd3d4} 16:44:08.028 [nioEventLoopGroup-1-0] INFO com.wlf.netty.nettyclient.handler.HeartBeatClientHandler - [client] Client send heart beat message to server : ----> NettyMessage{header=Header{delimiter=-1410399999, length=4, type=3, reserved=0}, data=[B@6cd2e1f8} 16:44:08.028 [nioEventLoopGroup-1-0] INFO com.wlf.netty.nettyclient.handler.HeartBeatClientHandler - [client] Client send business message to server : ----> NettyMessage{header=Header{delimiter=-1410399999, length=161800, type=1, reserved=0}, data=[B@3afcb3b5} 16:44:13.067 [nioEventLoopGroup-1-0] INFO com.wlf.netty.nettyclient.handler.HeartBeatClientHandler - [client] Client send heart beat message to server : ----> NettyMessage{header=Header{delimiter=-1410399999, length=4, type=3, reserved=0}, data=[B@af59570} 16:44:13.067 [nioEventLoopGroup-1-0] INFO com.wlf.netty.nettyclient.handler.HeartBeatClientHandler - [client] Client send business message to server : ----> NettyMessage{header=Header{delimiter=-1410399999, length=161800, type=1, reserved=0}, data=[B@5aa4e689} 16:44:18.071 [nioEventLoopGroup-1-0] INFO com.wlf.netty.nettyclient.handler.HeartBeatClientHandler - [client] Client send heart beat message to server : ----> NettyMessage{header=Header{delimiter=-1410399999, length=4, type=3, reserved=0}, data=[B@21821104} 16:44:18.071 [nioEventLoopGroup-1-0] INFO com.wlf.netty.nettyclient.handler.HeartBeatClientHandler - [client] Client send business message to server : ----> NettyMessage{header=Header{delimiter=-1410399999, length=161800, type=1, reserved=0}, data=[B@7ebc7f9a} 16:44:23.089 [nioEventLoopGroup-1-0] INFO com.wlf.netty.nettyclient.handler.HeartBeatClientHandler - [client] Client send heart beat message to server : ----> NettyMessage{header=Header{delimiter=-1410399999, length=4, type=3, reserved=0}, data=[B@58442b28} 16:44:23.089 [nioEventLoopGroup-1-0] INFO com.wlf.netty.nettyclient.handler.HeartBeatClientHandler - [client] Client send business message to server : ----> NettyMessage{header=Header{delimiter=-1410399999, length=161800, type=1, reserved=0}, data=[B@25a91e07} 16:44:28.112 [nioEventLoopGroup-1-0] INFO com.wlf.netty.nettyclient.handler.HeartBeatClientHandler - [client] Client send heart beat message to server : ----> NettyMessage{header=Header{delimiter=-1410399999, length=4, type=3, reserved=0}, data=[B@14122187} 16:44:28.112 [nioEventLoopGroup-1-0] INFO com.wlf.netty.nettyclient.handler.HeartBeatClientHandler - [client] Client send business message to server : ----> NettyMessage{header=Header{delimiter=-1410399999, length=161800, type=1, reserved=0}, data=[B@94fdc30} 16:44:33.121 [nioEventLoopGroup-1-0] INFO com.wlf.netty.nettyclient.handler.HeartBeatClientHandler - [client] Client send heart beat message to server : ----> NettyMessage{header=Header{delimiter=-1410399999, length=4, type=3, reserved=0}, data=[B@702bbb5a} 16:44:33.121 [nioEventLoopGroup-1-0] INFO com.wlf.netty.nettyclient.handler.HeartBeatClientHandler - [client] Client send business message to server : ----> NettyMessage{header=Header{delimiter=-1410399999, length=161800, type=1, reserved=0}, data=[B@1d1fda7e} 16:44:38.141 [nioEventLoopGroup-1-0] INFO com.wlf.netty.nettyclient.handler.HeartBeatClientHandler - [client] Client send heart beat message to server : ----> NettyMessage{header=Header{delimiter=-1410399999, length=4, type=3, reserved=0}, data=[B@1804ce43} 16:44:38.141 [nioEventLoopGroup-1-0] INFO com.wlf.netty.nettyclient.handler.HeartBeatClientHandler - [client] Client send business message to server : ----> NettyMessage{header=Header{delimiter=-1410399999, length=161800, type=1, reserved=0}, data=[B@6f5d2f2f} 16:44:43.159 [nioEventLoopGroup-1-0] INFO com.wlf.netty.nettyclient.handler.HeartBeatClientHandler - [client] Client send heart beat message to server : ----> NettyMessage{header=Header{delimiter=-1410399999, length=4, type=3, reserved=0}, data=[B@4201b8f5} 16:44:43.159 [nioEventLoopGroup-1-0] INFO com.wlf.netty.nettyclient.handler.HeartBeatClientHandler - [client] Client send business message to server : ----> NettyMessage{header=Header{delimiter=-1410399999, length=161800, type=1, reserved=0}, data=[B@21ae46e1} 16:44:48.181 [nioEventLoopGroup-1-0] INFO com.wlf.netty.nettyclient.handler.HeartBeatClientHandler - [client] Client send heart beat message to server : ----> NettyMessage{header=Header{delimiter=-1410399999, length=4, type=3, reserved=0}, data=[B@1f66f241} 16:44:48.181 [nioEventLoopGroup-1-0] INFO com.wlf.netty.nettyclient.handler.HeartBeatClientHandler - [client] Client send business message to server : ----> NettyMessage{header=Header{delimiter=-1410399999, length=161800, type=1, reserved=0}, data=[B@19c482d5} 16:44:53.206 [nioEventLoopGroup-1-0] INFO com.wlf.netty.nettyclient.handler.HeartBeatClientHandler - [client] Client send heart beat message to server : ----> NettyMessage{header=Header{delimiter=-1410399999, length=4, type=3, reserved=0}, data=[B@56cd4708} 16:44:53.206 [nioEventLoopGroup-1-0] INFO com.wlf.netty.nettyclient.handler.HeartBeatClientHandler - [client] Client send business message to server : ----> NettyMessage{header=Header{delimiter=-1410399999, length=161800, type=1, reserved=0}, data=[B@5879a7e} 16:44:58.215 [nioEventLoopGroup-1-0] INFO com.wlf.netty.nettyclient.handler.HeartBeatClientHandler - [client] Client send heart beat message to server : ----> NettyMessage{header=Header{delimiter=-1410399999, length=4, type=3, reserved=0}, data=[B@2d5b8475} 16:44:58.215 [nioEventLoopGroup-1-0] INFO com.wlf.netty.nettyclient.handler.HeartBeatClientHandler - [client] Client send business message to server : ----> NettyMessage{header=Header{delimiter=-1410399999, length=56098, type=1, reserved=0}, data=[B@10346921} 16:44:58.215 [nioEventLoopGroup-1-0] INFO com.wlf.netty.nettyclient.handler.HeartBeatClientHandler - The audio data send finish... 16:44:58.230 [nioEventLoopGroup-1-0] INFO com.wlf.netty.nettyclient.handler.HeartBeatClientHandler - [client] receive server business : NettyMessage{header=Header{delimiter=-1410399999, length=161800, type=2, reserved=0}, data=[B@2cfd9928} 16:44:58.230 [nioEventLoopGroup-1-0] INFO com.wlf.netty.nettyclient.handler.HeartBeatClientHandler - [client] receive server business : NettyMessage{header=Header{delimiter=-1410399999, length=161800, type=2, reserved=0}, data=[B@1510a2a3} 16:44:58.230 [nioEventLoopGroup-1-0] INFO com.wlf.netty.nettyclient.handler.HeartBeatClientHandler - [client] receive server business : NettyMessage{header=Header{delimiter=-1410399999, length=161800, type=2, reserved=0}, data=[B@6419e458} 16:44:58.230 [nioEventLoopGroup-1-0] INFO com.wlf.netty.nettyclient.handler.HeartBeatClientHandler - [client] receive server business : NettyMessage{header=Header{delimiter=-1410399999, length=161800, type=2, reserved=0}, data=[B@57d7e49b} 16:44:58.246 [nioEventLoopGroup-1-0] INFO com.wlf.netty.nettyclient.handler.HeartBeatClientHandler - [client] receive server business : NettyMessage{header=Header{delimiter=-1410399999, length=161800, type=2, reserved=0}, data=[B@17230390} 16:44:58.246 [nioEventLoopGroup-1-0] INFO com.wlf.netty.nettyclient.handler.HeartBeatClientHandler - [client] receive server business : NettyMessage{header=Header{delimiter=-1410399999, length=161800, type=2, reserved=0}, data=[B@736ae6d} 16:44:58.246 [nioEventLoopGroup-1-0] INFO com.wlf.netty.nettyclient.handler.HeartBeatClientHandler - [client] receive server business : NettyMessage{header=Header{delimiter=-1410399999, length=161800, type=2, reserved=0}, data=[B@2c26a1f7} 16:44:58.246 [nioEventLoopGroup-1-0] INFO com.wlf.netty.nettyclient.handler.HeartBeatClientHandler - [client] receive server business : NettyMessage{header=Header{delimiter=-1410399999, length=161800, type=2, reserved=0}, data=[B@443d7bd4} 16:44:58.246 [nioEventLoopGroup-1-0] INFO com.wlf.netty.nettyclient.handler.HeartBeatClientHandler - [client] receive server business : NettyMessage{header=Header{delimiter=-1410399999, length=161800, type=2, reserved=0}, data=[B@4b8dcf40} 16:44:58.246 [nioEventLoopGroup-1-0] INFO com.wlf.netty.nettyclient.handler.HeartBeatClientHandler - [client] receive server business : NettyMessage{header=Header{delimiter=-1410399999, length=161800, type=2, reserved=0}, data=[B@79fa559a} 16:44:58.246 [nioEventLoopGroup-1-0] INFO com.wlf.netty.nettyclient.handler.HeartBeatClientHandler - [client] receive server business : NettyMessage{header=Header{delimiter=-1410399999, length=161800, type=2, reserved=0}, data=[B@604a7a4b} 16:44:58.246 [nioEventLoopGroup-1-0] INFO com.wlf.netty.nettyclient.handler.HeartBeatClientHandler - [client] receive server business : NettyMessage{header=Header{delimiter=-1410399999, length=161800, type=2, reserved=0}, data=[B@4f064e4d} 16:44:58.246 [nioEventLoopGroup-1-0] INFO com.wlf.netty.nettyclient.handler.HeartBeatClientHandler - [client] receive server business : NettyMessage{header=Header{delimiter=-1410399999, length=161800, type=2, reserved=0}, data=[B@6a546f22} 16:44:58.261 [nioEventLoopGroup-1-0] INFO com.wlf.netty.nettyclient.handler.HeartBeatClientHandler - [client] receive server business : NettyMessage{header=Header{delimiter=-1410399999, length=161800, type=2, reserved=0}, data=[B@4129b177} 16:44:58.261 [nioEventLoopGroup-1-0] INFO com.wlf.netty.nettyclient.handler.HeartBeatClientHandler - [client] receive server business : NettyMessage{header=Header{delimiter=-1410399999, length=161800, type=2, reserved=0}, data=[B@7282033b} 16:44:58.261 [nioEventLoopGroup-1-0] INFO com.wlf.netty.nettyclient.handler.HeartBeatClientHandler - [client] receive server business : NettyMessage{header=Header{delimiter=-1410399999, length=161800, type=2, reserved=0}, data=[B@f0b5f00} 16:44:58.261 [nioEventLoopGroup-1-0] INFO com.wlf.netty.nettyclient.handler.HeartBeatClientHandler - [client] receive server business : NettyMessage{header=Header{delimiter=-1410399999, length=161800, type=2, reserved=0}, data=[B@46ef1cbc} 16:44:58.261 [nioEventLoopGroup-1-0] INFO com.wlf.netty.nettyclient.handler.HeartBeatClientHandler - [client] receive server business : NettyMessage{header=Header{delimiter=-1410399999, length=161800, type=2, reserved=0}, data=[B@4a41bf1f} 16:44:58.261 [nioEventLoopGroup-1-0] INFO com.wlf.netty.nettyclient.handler.HeartBeatClientHandler - [client] receive server business : NettyMessage{header=Header{delimiter=-1410399999, length=161800, type=2, reserved=0}, data=[B@28b8f6b7} 16:44:58.261 [nioEventLoopGroup-1-0] INFO com.wlf.netty.nettyclient.handler.HeartBeatClientHandler - [client] receive server business : NettyMessage{header=Header{delimiter=-1410399999, length=161800, type=2, reserved=0}, data=[B@7d9e5fff} 16:44:58.261 [nioEventLoopGroup-1-0] INFO com.wlf.netty.nettyclient.handler.HeartBeatClientHandler - [client] receive server business : NettyMessage{header=Header{delimiter=-1410399999, length=161800, type=2, reserved=0}, data=[B@43aab60c} 16:44:58.261 [nioEventLoopGroup-1-0] INFO com.wlf.netty.nettyclient.handler.HeartBeatClientHandler - [client] receive server business : NettyMessage{header=Header{delimiter=-1410399999, length=161800, type=2, reserved=0}, data=[B@4545021} 16:44:58.277 [nioEventLoopGroup-1-0] INFO com.wlf.netty.nettyclient.handler.HeartBeatClientHandler - [client] receive server business : NettyMessage{header=Header{delimiter=-1410399999, length=161800, type=2, reserved=0}, data=[B@6bb60352} 16:44:58.284 [nioEventLoopGroup-1-3] INFO com.wlf.netty.nettyclient.handler.HeartBeatClientHandler - [client] receive server business : NettyMessage{header=Header{delimiter=-1410399999, length=161800, type=2, reserved=0}, data=[B@2f09a1ad} 16:44:58.284 [nioEventLoopGroup-1-3] INFO com.wlf.netty.nettyclient.handler.HeartBeatClientHandler - [client] receive server business : NettyMessage{header=Header{delimiter=-1410399999, length=56098, type=2, reserved=0}, data=[B@dcaf48} 16:45:12.641 [nioEventLoopGroup-1-3] ERROR com.wlf.netty.nettyclient.handler.ControlClientHandler - [Client] conrol request error: java.lang.IndexOutOfBoundsException 16:45:12.641 [nioEventLoopGroup-1-3] ERROR com.wlf.netty.nettyclient.handler.HeartBeatClientHandler - [Client] heart request error: java.lang.IndexOutOfBoundsException 16:45:12.641 [nioEventLoopGroup-1-3] WARN io.netty.channel.DefaultChannelPipeline - An exceptionCaught() event was fired, and it reached at the tail of the pipeline. It usually means the last handler in the pipeline did not handle the exception. io.netty.handler.codec.DecoderException: java.lang.IndexOutOfBoundsException at io.netty.handler.codec.ByteToMessageDecoder.channelInactive(ByteToMessageDecoder.java:280) at io.netty.channel.ChannelHandlerInvokerUtil.invokeChannelInactiveNow(ChannelHandlerInvokerUtil.java:56) at io.netty.channel.DefaultChannelHandlerInvoker.invokeChannelInactive(DefaultChannelHandlerInvoker.java:92) at io.netty.channel.PausableChannelEventExecutor.invokeChannelInactive(PausableChannelEventExecutor.java:71) at io.netty.channel.AbstractChannelHandlerContext.fireChannelInactive(AbstractChannelHandlerContext.java:366) at io.netty.channel.DefaultChannelPipeline.fireChannelInactive(DefaultChannelPipeline.java:938) at io.netty.channel.AbstractChannel$AbstractUnsafe$7.run(AbstractChannel.java:680) at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:328) at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:354) at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:116) at io.netty.util.internal.chmv8.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1412) at io.netty.util.internal.chmv8.ForkJoinTask.doExec(ForkJoinTask.java:280) at io.netty.util.internal.chmv8.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:877) at io.netty.util.internal.chmv8.ForkJoinPool.scan(ForkJoinPool.java:1706) at io.netty.util.internal.chmv8.ForkJoinPool.runWorker(ForkJoinPool.java:1661) at io.netty.util.internal.chmv8.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:126) Caused by: java.lang.IndexOutOfBoundsException: null at io.netty.buffer.EmptyByteBuf.readInt(EmptyByteBuf.java:470) at com.wlf.netty.nettyapi.msgpack.NettyMessageDecoder.decode(NettyMessageDecoder.java:28) at io.netty.handler.codec.ByteToMessageDecoder.decodeLast(ByteToMessageDecoder.java:371) at io.netty.handler.codec.ByteToMessageDecoder.channelInactive(ByteToMessageDecoder.java:275) ... 15 common frames omitted Process finished with exit code 0
服务端输出:
16:42:52.708 [nioEventLoopGroup-1-0] INFO com.wlf.netty.nettyserver.handler.ControlServerHandler - [server] The control response is : NettyMessage{header=Header{delimiter=-1410399999, length=8, type=0, reserved=0}, data=[B@5e633e30}, data : [0, 0, 0, 86, 0, 0, 19, -120] 16:42:57.767 [nioEventLoopGroup-1-0] INFO com.wlf.netty.nettyserver.handler.HeartBeatServerHandler - [server] Receive client heart beat message : ----> NettyMessage{header=Header{delimiter=-1410399999, length=4, type=3, reserved=0}, data=[B@2ad4b5c2} 16:42:57.767 [nioEventLoopGroup-1-0] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - [server] server receive client message : NettyMessage{header=Header{delimiter=-1410399999, length=161800, type=1, reserved=0}, data=[B@728137b7} 16:42:57.767 [nioEventLoopGroup-1-0] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - data length: 161800 16:42:57.767 [nioEventLoopGroup-1-0] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - startTime: 1572252177730 16:42:57.767 [nioEventLoopGroup-1-0] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - [server] send to client : NettyMessage{header=Header{delimiter=-1410399999, length=161800, type=2, reserved=0}, data=[B@728137b7} 16:43:02.637 [nioEventLoopGroup-1-0] INFO com.wlf.netty.nettyserver.handler.HeartBeatServerHandler - isReceiveHeart : true 16:43:02.637 [nioEventLoopGroup-1-0] INFO com.wlf.netty.nettyserver.handler.HeartBeatServerHandler - [server] heart timeOut is : 4870 ms 16:43:02.776 [nioEventLoopGroup-1-0] INFO com.wlf.netty.nettyserver.handler.HeartBeatServerHandler - [server] Receive client heart beat message : ----> NettyMessage{header=Header{delimiter=-1410399999, length=4, type=3, reserved=0}, data=[B@27dbeee1} 16:43:02.822 [nioEventLoopGroup-1-2] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - [server] server receive client message : NettyMessage{header=Header{delimiter=-1410399999, length=161800, type=1, reserved=0}, data=[B@26d3ec52} 16:43:02.822 [nioEventLoopGroup-1-2] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - data length: 161800 16:43:02.822 [nioEventLoopGroup-1-2] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - startTime: 1572252182776 16:43:02.822 [nioEventLoopGroup-1-2] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - [server] send to client : NettyMessage{header=Header{delimiter=-1410399999, length=161800, type=2, reserved=0}, data=[B@26d3ec52} 16:43:07.813 [nioEventLoopGroup-1-2] INFO com.wlf.netty.nettyserver.handler.HeartBeatServerHandler - [server] Receive client heart beat message : ----> NettyMessage{header=Header{delimiter=-1410399999, length=4, type=3, reserved=0}, data=[B@658728ad} 16:43:07.844 [nioEventLoopGroup-1-3] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - [server] server receive client message : NettyMessage{header=Header{delimiter=-1410399999, length=161800, type=1, reserved=0}, data=[B@2c5508ae} 16:43:07.844 [nioEventLoopGroup-1-3] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - data length: 161800 16:43:07.844 [nioEventLoopGroup-1-3] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - startTime: 1572252187798 16:43:07.844 [nioEventLoopGroup-1-3] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - [server] send to client : NettyMessage{header=Header{delimiter=-1410399999, length=161800, type=2, reserved=0}, data=[B@2c5508ae} 16:43:12.638 [nioEventLoopGroup-1-3] INFO com.wlf.netty.nettyserver.handler.HeartBeatServerHandler - isReceiveHeart : true 16:43:12.638 [nioEventLoopGroup-1-3] INFO com.wlf.netty.nettyserver.handler.HeartBeatServerHandler - [server] heart timeOut is : 0 ms 16:43:12.839 [nioEventLoopGroup-1-3] INFO com.wlf.netty.nettyserver.handler.HeartBeatServerHandler - [server] Receive client heart beat message : ----> NettyMessage{header=Header{delimiter=-1410399999, length=4, type=3, reserved=0}, data=[B@286a89fc} 16:43:12.854 [nioEventLoopGroup-1-3] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - [server] server receive client message : NettyMessage{header=Header{delimiter=-1410399999, length=161800, type=1, reserved=0}, data=[B@6d680295} 16:43:12.854 [nioEventLoopGroup-1-3] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - data length: 161800 16:43:12.854 [nioEventLoopGroup-1-3] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - startTime: 1572252192839 16:43:12.854 [nioEventLoopGroup-1-3] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - [server] send to client : NettyMessage{header=Header{delimiter=-1410399999, length=161800, type=2, reserved=0}, data=[B@6d680295} 16:43:17.878 [nioEventLoopGroup-1-3] INFO com.wlf.netty.nettyserver.handler.HeartBeatServerHandler - [server] Receive client heart beat message : ----> NettyMessage{header=Header{delimiter=-1410399999, length=4, type=3, reserved=0}, data=[B@58db0b36} 16:43:17.878 [nioEventLoopGroup-1-3] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - [server] server receive client message : NettyMessage{header=Header{delimiter=-1410399999, length=161800, type=1, reserved=0}, data=[B@5c4f68fb} 16:43:17.878 [nioEventLoopGroup-1-3] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - data length: 161800 16:43:17.878 [nioEventLoopGroup-1-3] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - startTime: 1572252197863 16:43:17.878 [nioEventLoopGroup-1-3] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - [server] send to client : NettyMessage{header=Header{delimiter=-1410399999, length=161800, type=2, reserved=0}, data=[B@5c4f68fb} 16:43:22.646 [nioEventLoopGroup-1-3] INFO com.wlf.netty.nettyserver.handler.HeartBeatServerHandler - isReceiveHeart : true 16:43:22.646 [nioEventLoopGroup-1-3] INFO com.wlf.netty.nettyserver.handler.HeartBeatServerHandler - [server] heart timeOut is : 4768 ms 16:43:22.884 [nioEventLoopGroup-1-3] INFO com.wlf.netty.nettyserver.handler.HeartBeatServerHandler - [server] Receive client heart beat message : ----> NettyMessage{header=Header{delimiter=-1410399999, length=4, type=3, reserved=0}, data=[B@20163fe7} 16:43:22.884 [nioEventLoopGroup-1-3] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - [server] server receive client message : NettyMessage{header=Header{delimiter=-1410399999, length=161800, type=1, reserved=0}, data=[B@d47fdda} 16:43:22.884 [nioEventLoopGroup-1-3] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - data length: 161800 16:43:22.884 [nioEventLoopGroup-1-3] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - startTime: 1572252202869 16:43:22.884 [nioEventLoopGroup-1-3] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - [server] send to client : NettyMessage{header=Header{delimiter=-1410399999, length=161800, type=2, reserved=0}, data=[B@d47fdda} 16:43:27.893 [nioEventLoopGroup-1-3] INFO com.wlf.netty.nettyserver.handler.HeartBeatServerHandler - [server] Receive client heart beat message : ----> NettyMessage{header=Header{delimiter=-1410399999, length=4, type=3, reserved=0}, data=[B@d45d5ff} 16:43:27.908 [nioEventLoopGroup-1-3] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - [server] server receive client message : NettyMessage{header=Header{delimiter=-1410399999, length=161800, type=1, reserved=0}, data=[B@2aea6c1c} 16:43:27.908 [nioEventLoopGroup-1-3] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - data length: 161800 16:43:27.908 [nioEventLoopGroup-1-3] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - startTime: 1572252207893 16:43:27.908 [nioEventLoopGroup-1-3] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - [server] send to client : NettyMessage{header=Header{delimiter=-1410399999, length=161800, type=2, reserved=0}, data=[B@2aea6c1c} 16:43:32.634 [nioEventLoopGroup-1-3] INFO com.wlf.netty.nettyserver.handler.HeartBeatServerHandler - isReceiveHeart : true 16:43:32.634 [nioEventLoopGroup-1-3] INFO com.wlf.netty.nettyserver.handler.HeartBeatServerHandler - [server] heart timeOut is : 4741 ms 16:43:32.935 [nioEventLoopGroup-1-3] INFO com.wlf.netty.nettyserver.handler.HeartBeatServerHandler - [server] Receive client heart beat message : ----> NettyMessage{header=Header{delimiter=-1410399999, length=4, type=3, reserved=0}, data=[B@3b1297a1} 16:43:32.935 [nioEventLoopGroup-1-3] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - [server] server receive client message : NettyMessage{header=Header{delimiter=-1410399999, length=161800, type=1, reserved=0}, data=[B@9090434} 16:43:32.935 [nioEventLoopGroup-1-3] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - data length: 161800 16:43:32.935 [nioEventLoopGroup-1-3] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - startTime: 1572252212920 16:43:32.935 [nioEventLoopGroup-1-3] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - [server] send to client : NettyMessage{header=Header{delimiter=-1410399999, length=161800, type=2, reserved=0}, data=[B@9090434} 16:43:37.943 [nioEventLoopGroup-1-3] INFO com.wlf.netty.nettyserver.handler.HeartBeatServerHandler - [server] Receive client heart beat message : ----> NettyMessage{header=Header{delimiter=-1410399999, length=4, type=3, reserved=0}, data=[B@2ac0c2c7} 16:43:37.958 [nioEventLoopGroup-1-3] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - [server] server receive client message : NettyMessage{header=Header{delimiter=-1410399999, length=161800, type=1, reserved=0}, data=[B@53b3c10f} 16:43:37.958 [nioEventLoopGroup-1-3] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - data length: 161800 16:43:37.958 [nioEventLoopGroup-1-3] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - startTime: 1572252217943 16:43:37.958 [nioEventLoopGroup-1-3] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - [server] send to client : NettyMessage{header=Header{delimiter=-1410399999, length=161800, type=2, reserved=0}, data=[B@53b3c10f} 16:43:42.643 [nioEventLoopGroup-1-3] INFO com.wlf.netty.nettyserver.handler.HeartBeatServerHandler - isReceiveHeart : true 16:43:42.643 [nioEventLoopGroup-1-3] INFO com.wlf.netty.nettyserver.handler.HeartBeatServerHandler - [server] heart timeOut is : 4700 ms 16:43:42.951 [nioEventLoopGroup-1-3] INFO com.wlf.netty.nettyserver.handler.HeartBeatServerHandler - [server] Receive client heart beat message : ----> NettyMessage{header=Header{delimiter=-1410399999, length=4, type=3, reserved=0}, data=[B@7c33eb47} 16:43:42.951 [nioEventLoopGroup-1-3] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - [server] server receive client message : NettyMessage{header=Header{delimiter=-1410399999, length=161800, type=1, reserved=0}, data=[B@3d5a7851} 16:43:42.951 [nioEventLoopGroup-1-3] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - data length: 161800 16:43:42.951 [nioEventLoopGroup-1-3] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - startTime: 1572252222945 16:43:42.951 [nioEventLoopGroup-1-3] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - [server] send to client : NettyMessage{header=Header{delimiter=-1410399999, length=161800, type=2, reserved=0}, data=[B@3d5a7851} 16:43:47.967 [nioEventLoopGroup-1-3] INFO com.wlf.netty.nettyserver.handler.HeartBeatServerHandler - [server] Receive client heart beat message : ----> NettyMessage{header=Header{delimiter=-1410399999, length=4, type=3, reserved=0}, data=[B@11a043c7} 16:43:47.974 [nioEventLoopGroup-1-3] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - [server] server receive client message : NettyMessage{header=Header{delimiter=-1410399999, length=161800, type=1, reserved=0}, data=[B@5c565345} 16:43:47.974 [nioEventLoopGroup-1-3] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - data length: 161800 16:43:47.974 [nioEventLoopGroup-1-3] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - startTime: 1572252227952 16:43:47.974 [nioEventLoopGroup-1-3] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - [server] send to client : NettyMessage{header=Header{delimiter=-1410399999, length=161800, type=2, reserved=0}, data=[B@5c565345} 16:43:52.642 [nioEventLoopGroup-1-3] INFO com.wlf.netty.nettyserver.handler.HeartBeatServerHandler - isReceiveHeart : true 16:43:52.642 [nioEventLoopGroup-1-3] INFO com.wlf.netty.nettyserver.handler.HeartBeatServerHandler - [server] heart timeOut is : 4675 ms 16:43:52.974 [nioEventLoopGroup-1-3] INFO com.wlf.netty.nettyserver.handler.HeartBeatServerHandler - [server] Receive client heart beat message : ----> NettyMessage{header=Header{delimiter=-1410399999, length=4, type=3, reserved=0}, data=[B@3f5cf25b} 16:43:52.989 [nioEventLoopGroup-1-3] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - [server] server receive client message : NettyMessage{header=Header{delimiter=-1410399999, length=161800, type=1, reserved=0}, data=[B@51aa8d11} 16:43:52.989 [nioEventLoopGroup-1-3] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - data length: 161800 16:43:52.989 [nioEventLoopGroup-1-3] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - startTime: 1572252232974 16:43:52.989 [nioEventLoopGroup-1-3] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - [server] send to client : NettyMessage{header=Header{delimiter=-1410399999, length=161800, type=2, reserved=0}, data=[B@51aa8d11} 16:43:58.012 [nioEventLoopGroup-1-3] INFO com.wlf.netty.nettyserver.handler.HeartBeatServerHandler - [server] Receive client heart beat message : ----> NettyMessage{header=Header{delimiter=-1410399999, length=4, type=3, reserved=0}, data=[B@42875298} 16:43:58.019 [nioEventLoopGroup-1-3] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - [server] server receive client message : NettyMessage{header=Header{delimiter=-1410399999, length=161800, type=1, reserved=0}, data=[B@2c25edf6} 16:43:58.019 [nioEventLoopGroup-1-3] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - data length: 161800 16:43:58.019 [nioEventLoopGroup-1-3] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - startTime: 1572252237997 16:43:58.019 [nioEventLoopGroup-1-3] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - [server] send to client : NettyMessage{header=Header{delimiter=-1410399999, length=161800, type=2, reserved=0}, data=[B@2c25edf6} 16:44:02.633 [nioEventLoopGroup-1-3] INFO com.wlf.netty.nettyserver.handler.HeartBeatServerHandler - isReceiveHeart : true 16:44:02.633 [nioEventLoopGroup-1-3] INFO com.wlf.netty.nettyserver.handler.HeartBeatServerHandler - [server] heart timeOut is : 4621 ms 16:44:03.020 [nioEventLoopGroup-1-3] INFO com.wlf.netty.nettyserver.handler.HeartBeatServerHandler - [server] Receive client heart beat message : ----> NettyMessage{header=Header{delimiter=-1410399999, length=4, type=3, reserved=0}, data=[B@74b30c03} 16:44:03.020 [nioEventLoopGroup-1-3] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - [server] server receive client message : NettyMessage{header=Header{delimiter=-1410399999, length=161800, type=1, reserved=0}, data=[B@71f4c581} 16:44:03.035 [nioEventLoopGroup-1-3] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - data length: 161800 16:44:03.035 [nioEventLoopGroup-1-3] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - startTime: 1572252243020 16:44:03.035 [nioEventLoopGroup-1-3] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - [server] send to client : NettyMessage{header=Header{delimiter=-1410399999, length=161800, type=2, reserved=0}, data=[B@71f4c581} 16:44:08.065 [nioEventLoopGroup-1-5] INFO com.wlf.netty.nettyserver.handler.HeartBeatServerHandler - [server] Receive client heart beat message : ----> NettyMessage{header=Header{delimiter=-1410399999, length=4, type=3, reserved=0}, data=[B@4536f39f} 16:44:08.065 [nioEventLoopGroup-1-5] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - [server] server receive client message : NettyMessage{header=Header{delimiter=-1410399999, length=161800, type=1, reserved=0}, data=[B@4bf10549} 16:44:08.065 [nioEventLoopGroup-1-5] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - data length: 161800 16:44:08.065 [nioEventLoopGroup-1-5] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - startTime: 1572252248028 16:44:08.065 [nioEventLoopGroup-1-5] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - [server] send to client : NettyMessage{header=Header{delimiter=-1410399999, length=161800, type=2, reserved=0}, data=[B@4bf10549} 16:44:12.634 [nioEventLoopGroup-1-5] INFO com.wlf.netty.nettyserver.handler.HeartBeatServerHandler - isReceiveHeart : true 16:44:12.634 [nioEventLoopGroup-1-5] INFO com.wlf.netty.nettyserver.handler.HeartBeatServerHandler - [server] heart timeOut is : 4569 ms 16:44:13.067 [nioEventLoopGroup-1-5] INFO com.wlf.netty.nettyserver.handler.HeartBeatServerHandler - [server] Receive client heart beat message : ----> NettyMessage{header=Header{delimiter=-1410399999, length=4, type=3, reserved=0}, data=[B@4fce98ef} 16:44:13.067 [nioEventLoopGroup-1-5] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - [server] server receive client message : NettyMessage{header=Header{delimiter=-1410399999, length=161800, type=1, reserved=0}, data=[B@acc0f72} 16:44:13.067 [nioEventLoopGroup-1-5] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - data length: 161800 16:44:13.067 [nioEventLoopGroup-1-5] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - startTime: 1572252253052 16:44:13.067 [nioEventLoopGroup-1-5] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - [server] send to client : NettyMessage{header=Header{delimiter=-1410399999, length=161800, type=2, reserved=0}, data=[B@acc0f72} 16:44:18.071 [nioEventLoopGroup-1-5] INFO com.wlf.netty.nettyserver.handler.HeartBeatServerHandler - [server] Receive client heart beat message : ----> NettyMessage{header=Header{delimiter=-1410399999, length=4, type=3, reserved=0}, data=[B@7894bfbf} 16:44:18.086 [nioEventLoopGroup-1-5] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - [server] server receive client message : NettyMessage{header=Header{delimiter=-1410399999, length=161800, type=1, reserved=0}, data=[B@3b0c26a9} 16:44:18.086 [nioEventLoopGroup-1-5] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - data length: 161800 16:44:18.086 [nioEventLoopGroup-1-5] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - startTime: 1572252258071 16:44:18.086 [nioEventLoopGroup-1-5] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - [server] send to client : NettyMessage{header=Header{delimiter=-1410399999, length=161800, type=2, reserved=0}, data=[B@3b0c26a9} 16:44:22.639 [nioEventLoopGroup-1-5] INFO com.wlf.netty.nettyserver.handler.HeartBeatServerHandler - isReceiveHeart : true 16:44:22.639 [nioEventLoopGroup-1-5] INFO com.wlf.netty.nettyserver.handler.HeartBeatServerHandler - [server] heart timeOut is : 4568 ms 16:44:23.089 [nioEventLoopGroup-1-5] INFO com.wlf.netty.nettyserver.handler.HeartBeatServerHandler - [server] Receive client heart beat message : ----> NettyMessage{header=Header{delimiter=-1410399999, length=4, type=3, reserved=0}, data=[B@bec8c7} 16:44:23.104 [nioEventLoopGroup-1-5] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - [server] server receive client message : NettyMessage{header=Header{delimiter=-1410399999, length=161800, type=1, reserved=0}, data=[B@6ae3f03d} 16:44:23.104 [nioEventLoopGroup-1-5] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - data length: 161800 16:44:23.104 [nioEventLoopGroup-1-5] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - startTime: 1572252263089 16:44:23.104 [nioEventLoopGroup-1-5] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - [server] send to client : NettyMessage{header=Header{delimiter=-1410399999, length=161800, type=2, reserved=0}, data=[B@6ae3f03d} 16:44:28.112 [nioEventLoopGroup-1-5] INFO com.wlf.netty.nettyserver.handler.HeartBeatServerHandler - [server] Receive client heart beat message : ----> NettyMessage{header=Header{delimiter=-1410399999, length=4, type=3, reserved=0}, data=[B@3757d399} 16:44:28.112 [nioEventLoopGroup-1-5] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - [server] server receive client message : NettyMessage{header=Header{delimiter=-1410399999, length=161800, type=1, reserved=0}, data=[B@6d3492b4} 16:44:28.127 [nioEventLoopGroup-1-5] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - data length: 161800 16:44:28.127 [nioEventLoopGroup-1-5] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - startTime: 1572252268112 16:44:28.127 [nioEventLoopGroup-1-5] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - [server] send to client : NettyMessage{header=Header{delimiter=-1410399999, length=161800, type=2, reserved=0}, data=[B@6d3492b4} 16:44:32.634 [nioEventLoopGroup-1-5] INFO com.wlf.netty.nettyserver.handler.HeartBeatServerHandler - isReceiveHeart : true 16:44:32.634 [nioEventLoopGroup-1-5] INFO com.wlf.netty.nettyserver.handler.HeartBeatServerHandler - [server] heart timeOut is : 4522 ms 16:44:33.121 [nioEventLoopGroup-1-5] INFO com.wlf.netty.nettyserver.handler.HeartBeatServerHandler - [server] Receive client heart beat message : ----> NettyMessage{header=Header{delimiter=-1410399999, length=4, type=3, reserved=0}, data=[B@1bba8725} 16:44:33.136 [nioEventLoopGroup-1-5] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - [server] server receive client message : NettyMessage{header=Header{delimiter=-1410399999, length=161800, type=1, reserved=0}, data=[B@6eadee77} 16:44:33.136 [nioEventLoopGroup-1-5] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - data length: 161800 16:44:33.136 [nioEventLoopGroup-1-5] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - startTime: 1572252273121 16:44:33.136 [nioEventLoopGroup-1-5] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - [server] send to client : NettyMessage{header=Header{delimiter=-1410399999, length=161800, type=2, reserved=0}, data=[B@6eadee77} 16:44:38.141 [nioEventLoopGroup-1-5] INFO com.wlf.netty.nettyserver.handler.HeartBeatServerHandler - [server] Receive client heart beat message : ----> NettyMessage{header=Header{delimiter=-1410399999, length=4, type=3, reserved=0}, data=[B@676f2320} 16:44:38.156 [nioEventLoopGroup-1-5] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - [server] server receive client message : NettyMessage{header=Header{delimiter=-1410399999, length=161800, type=1, reserved=0}, data=[B@2e87ac4b} 16:44:38.156 [nioEventLoopGroup-1-5] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - data length: 161800 16:44:38.156 [nioEventLoopGroup-1-5] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - startTime: 1572252278141 16:44:38.156 [nioEventLoopGroup-1-5] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - [server] send to client : NettyMessage{header=Header{delimiter=-1410399999, length=161800, type=2, reserved=0}, data=[B@2e87ac4b} 16:44:42.641 [nioEventLoopGroup-1-5] INFO com.wlf.netty.nettyserver.handler.HeartBeatServerHandler - isReceiveHeart : true 16:44:42.641 [nioEventLoopGroup-1-5] INFO com.wlf.netty.nettyserver.handler.HeartBeatServerHandler - [server] heart timeOut is : 4500 ms 16:44:43.159 [nioEventLoopGroup-1-5] INFO com.wlf.netty.nettyserver.handler.HeartBeatServerHandler - [server] Receive client heart beat message : ----> NettyMessage{header=Header{delimiter=-1410399999, length=4, type=3, reserved=0}, data=[B@614b9511} 16:44:43.174 [nioEventLoopGroup-1-5] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - [server] server receive client message : NettyMessage{header=Header{delimiter=-1410399999, length=161800, type=1, reserved=0}, data=[B@60140119} 16:44:43.174 [nioEventLoopGroup-1-5] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - data length: 161800 16:44:43.174 [nioEventLoopGroup-1-5] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - startTime: 1572252283159 16:44:43.174 [nioEventLoopGroup-1-5] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - [server] send to client : NettyMessage{header=Header{delimiter=-1410399999, length=161800, type=2, reserved=0}, data=[B@60140119} 16:44:48.181 [nioEventLoopGroup-1-5] INFO com.wlf.netty.nettyserver.handler.HeartBeatServerHandler - [server] Receive client heart beat message : ----> NettyMessage{header=Header{delimiter=-1410399999, length=4, type=3, reserved=0}, data=[B@7efc5818} 16:44:48.196 [nioEventLoopGroup-1-5] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - [server] server receive client message : NettyMessage{header=Header{delimiter=-1410399999, length=161800, type=1, reserved=0}, data=[B@6d8a5678} 16:44:48.196 [nioEventLoopGroup-1-5] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - data length: 161800 16:44:48.196 [nioEventLoopGroup-1-5] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - startTime: 1572252288181 16:44:48.196 [nioEventLoopGroup-1-5] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - [server] send to client : NettyMessage{header=Header{delimiter=-1410399999, length=161800, type=2, reserved=0}, data=[B@6d8a5678} 16:44:52.634 [nioEventLoopGroup-1-5] INFO com.wlf.netty.nettyserver.handler.HeartBeatServerHandler - isReceiveHeart : true 16:44:52.634 [nioEventLoopGroup-1-5] INFO com.wlf.netty.nettyserver.handler.HeartBeatServerHandler - [server] heart timeOut is : 4453 ms 16:44:53.206 [nioEventLoopGroup-1-5] INFO com.wlf.netty.nettyserver.handler.HeartBeatServerHandler - [server] Receive client heart beat message : ----> NettyMessage{header=Header{delimiter=-1410399999, length=4, type=3, reserved=0}, data=[B@50d4a5c5} 16:44:53.221 [nioEventLoopGroup-1-5] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - [server] server receive client message : NettyMessage{header=Header{delimiter=-1410399999, length=161800, type=1, reserved=0}, data=[B@10086a0f} 16:44:53.221 [nioEventLoopGroup-1-5] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - data length: 161800 16:44:53.221 [nioEventLoopGroup-1-5] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - startTime: 1572252293206 16:44:53.221 [nioEventLoopGroup-1-5] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - [server] send to client : NettyMessage{header=Header{delimiter=-1410399999, length=161800, type=2, reserved=0}, data=[B@10086a0f} 16:44:58.215 [nioEventLoopGroup-1-5] INFO com.wlf.netty.nettyserver.handler.HeartBeatServerHandler - [server] Receive client heart beat message : ----> NettyMessage{header=Header{delimiter=-1410399999, length=4, type=3, reserved=0}, data=[B@c28cc8e} 16:44:58.215 [nioEventLoopGroup-1-5] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - [server] server receive client message : NettyMessage{header=Header{delimiter=-1410399999, length=56098, type=1, reserved=0}, data=[B@332e62e5} 16:44:58.215 [nioEventLoopGroup-1-5] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - data length: 56098 16:44:58.215 [nioEventLoopGroup-1-5] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - startTime: 1572252298215 16:44:58.215 [nioEventLoopGroup-1-5] INFO com.wlf.netty.nettyserver.handler.NettyServerHandler - [server] send to client : NettyMessage{header=Header{delimiter=-1410399999, length=56098, type=2, reserved=0}, data=[B@332e62e5} 16:45:02.647 [nioEventLoopGroup-1-5] INFO com.wlf.netty.nettyserver.handler.HeartBeatServerHandler - isReceiveHeart : true 16:45:02.647 [nioEventLoopGroup-1-5] INFO com.wlf.netty.nettyserver.handler.HeartBeatServerHandler - [server] heart timeOut is : 4432 ms 16:45:12.635 [nioEventLoopGroup-1-5] INFO com.wlf.netty.nettyserver.handler.HeartBeatServerHandler - isReceiveHeart : true 16:45:12.635 [nioEventLoopGroup-1-5] INFO com.wlf.netty.nettyserver.handler.HeartBeatServerHandler - [server] heart timeOut is : 14420 ms 16:45:12.635 [nioEventLoopGroup-1-5] ERROR com.wlf.netty.nettyserver.handler.HeartBeatServerHandler - [server] heart beat time out. 16:45:12.635 [nioEventLoopGroup-1-5] ERROR com.wlf.netty.nettyserver.handler.ControlServerHandler - [server] control response error: java.lang.IndexOutOfBoundsException 16:45:12.635 [nioEventLoopGroup-1-5] ERROR com.wlf.netty.nettyserver.handler.HeartBeatServerHandler - [server] heart response error: java.lang.IndexOutOfBoundsException 16:45:12.641 [nioEventLoopGroup-1-5] ERROR com.wlf.netty.nettyserver.handler.NettyServerHandler - server received failed, error : java.lang.IndexOutOfBoundsException io.netty.handler.codec.DecoderException: java.lang.IndexOutOfBoundsException at io.netty.handler.codec.ByteToMessageDecoder.channelInactive(ByteToMessageDecoder.java:280) at io.netty.channel.ChannelHandlerInvokerUtil.invokeChannelInactiveNow(ChannelHandlerInvokerUtil.java:56) at io.netty.channel.DefaultChannelHandlerInvoker.invokeChannelInactive(DefaultChannelHandlerInvoker.java:92) at io.netty.channel.PausableChannelEventExecutor.invokeChannelInactive(PausableChannelEventExecutor.java:71) at io.netty.channel.AbstractChannelHandlerContext.fireChannelInactive(AbstractChannelHandlerContext.java:366) at io.netty.channel.DefaultChannelPipeline.fireChannelInactive(DefaultChannelPipeline.java:938) at io.netty.channel.AbstractChannel$AbstractUnsafe$7.run(AbstractChannel.java:680) at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:328) at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:354) at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:116) at io.netty.util.internal.chmv8.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1412) at io.netty.util.internal.chmv8.ForkJoinTask.doExec(ForkJoinTask.java:280) at io.netty.util.internal.chmv8.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:877) at io.netty.util.internal.chmv8.ForkJoinPool.scan(ForkJoinPool.java:1706) at io.netty.util.internal.chmv8.ForkJoinPool.runWorker(ForkJoinPool.java:1661) at io.netty.util.internal.chmv8.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:126) Caused by: java.lang.IndexOutOfBoundsException at io.netty.buffer.EmptyByteBuf.readInt(EmptyByteBuf.java:470) at com.wlf.netty.nettyapi.msgpack.NettyMessageDecoder.decode(NettyMessageDecoder.java:28) at io.netty.handler.codec.ByteToMessageDecoder.decodeLast(ByteToMessageDecoder.java:371) at io.netty.handler.codec.ByteToMessageDecoder.channelInactive(ByteToMessageDecoder.java:275) ... 15 more
从上面标黄处可以看到,服务端先断开,客户端感知到后退出了程序。