客户端每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

  从上面标黄处可以看到,服务端先断开,客户端感知到后退出了程序。

netty5服务端检测心跳超时断连的更多相关文章

  1. netty服务端实现心跳超时的主动拆链

    一.服务器启动示例: public class MySocketServer { protected static Logger logger = LoggerFactory.getLogger(My ...

  2. Netty5服务端源码解析

    Netty5源码解析 今天让我来总结下netty5的服务端代码. 服务端(ServerBootstrap) 示例代码如下: import io.netty.bootstrap.ServerBootst ...

  3. Netty4 学习笔记之二:客户端与服务端心跳 demo

    前言 在上一篇Netty demo 中,了解了Netty中的客户端和服务端之间的通信.这篇则介绍Netty中的心跳. 之前在Mina 中心跳的使用是通过继承 KeepAliveMessageFacto ...

  4. .NET 即时通信,WebSocket服务端实例

    即时通信常用手段 1.第三方平台 谷歌.腾讯 环信等多如牛毛,其中谷歌即时通信是免费的,但免费就是免费的并不好用.其他的一些第三方一般收费的,使用要则限流(1s/限制x条消息)要么则限制用户数. 但稳 ...

  5. .NET实现WebSocket服务端即时通信实例

    即时通信常用手段 1.第三方平台 谷歌.腾讯 环信等多如牛毛,其中谷歌即时通信是免费的,但免费就是免费的并不好用.其他的一些第三方一般收费的,使用要则限流(1s/限制x条消息)要么则限制用户数. 但稳 ...

  6. 服务端事件EventSource揭秘

    服务端推 服务端推,指的是由服务器主动的向客户端发送消息(响应).在应用层的HTTP协议实现中,"请求-响应"是一个round trip,它的起点来自客户端,因此在应用层之上无法实 ...

  7. 客户端与服务端的事件watcher源码阅读

    watcher存在的必要性 举个特容易懂的例子: 假如我的项目是基于dubbo+zookeeper搭建的分布式项目, 我有三个功能相同的服务提供者,用zookeeper当成注册中心,我的三个项目得注册 ...

  8. select引起的服务端程序崩溃问题

    现象: 某个线上的服务最近频繁崩溃.该服务使用C++编写,是个网络服务端程序.作为TCP服务端,接收和转发客户端发来的消息,并给客户端发送消息.该服务跑在CentOS上,8G内存.线上环境中,与客户端 ...

  9. Netty实现服务端客户端长连接通讯及心跳检测

    通过netty实现服务端与客户端的长连接通讯,及心跳检测.        基本思路:netty服务端通过一个Map保存所有连接上来的客户端SocketChannel,客户端的Id作为Map的key.每 ...

随机推荐

  1. git config user.name

    Setting your username in Git Git uses a username to associate commits with an identity. The Git user ...

  2. WPF + SelfHost 实现窗体自宿主(API,API和窗体通信)

    前言 今天研究了在 WPF 中使用 SelfHost 自宿主. 具体的功能是,在 WPF 中使用自宿主服务,外部调用服务的 API,在 API 里面操作窗体的显示等. 技术点 在 WPF 中集成 Se ...

  3. js的异常处理 try catch

    <script language="JavaScript"> try { throw new Error(10,"asdasdasd") } cat ...

  4. “挂起”bug处理执行方案

    目的:避免bug状态改为挂起后,就无人问津,导致一直未得到解决.因而影响用户的使用与产品质量较差.

  5. php 递归算法

    通过递归实现阶乘 function multi($n){ if($n == 0){ return 1 ;//终止递归 } $value = $n * multi($n-1); return $valu ...

  6. python 类 双下划线解析

    __getattr__用法:说明:这是python里的一个内建函数,当调用的属性或者方法不存在时,该方法会被调用调用不存在的属性调用不存在的方法

  7. js模拟滚动条滚动

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  8. Java基础学习【字符串倒序输出+排序】

    字符串逆序输出 import java.util.*; public class Main{ public static void main(String [] args) { //字符串逆序输出 S ...

  9. 谈谈对Spring的理解

    转载自:  https://blog.csdn.net/qq_41701956/article/details/90453716 Spring 框架是 Java 应用最广的框架,它的成功来源于理念,而 ...

  10. Nginx 负载均衡演示之 upstream 参数 & location 参数

    upstream 参数nginx关于upstream参数官方文档:http://nginx.org/en/docs/http/ngx_http_upstream_module.html upstrea ...