作者 crossoverJie

:sparkles: Introducing new features.服务端心跳检测2

... ... @@ -3,6 +3,7 @@ package com.crossoverjie.cim.client.handle;
import com.crossoverjie.cim.client.util.SpringBeanFactory;
import com.crossoverjie.cim.common.protocol.CIMRequestProto;
import com.crossoverjie.cim.common.protocol.CIMResponseProto;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
... ... @@ -39,7 +40,7 @@ public class CIMClientHandle extends SimpleChannelInboundHandler<CIMResponseProt
if (idleStateEvent.state() == IdleState.WRITER_IDLE){
CIMRequestProto.CIMReqProtocol heartBeat = SpringBeanFactory.getBean("heartBeat",
CIMRequestProto.CIMReqProtocol.class);
ctx.writeAndFlush(heartBeat) ;
ctx.writeAndFlush(heartBeat).addListeners(ChannelFutureListener.CLOSE_ON_FAILURE) ;
}
... ...
... ... @@ -58,9 +58,13 @@ public class CIMServerHandle extends SimpleChannelInboundHandler<CIMRequestProto
@Override
public void operationComplete(ChannelFuture future) throws Exception {
if (!future.isSuccess()) {
LOGGER.info("向客户端发送心跳失败");
//下线客户端
CIMUserInfo userInfo = SessionSocketHolder.getUserId((NioSocketChannel) future.channel());
userOffLine(userInfo, (NioSocketChannel) future.channel());
future.channel().close();
}else {
LOGGER.info("向客户端发送心跳成功");
}
}
});
... ...