做招聘网站需要人力资源许可,一个人可以做几个网站负责人,能注册通用网址的网站,济南seo网站推广公司客户端与服务端断开有两种情况#xff1a;
1.正常断开#xff0c;客户端调用了ctx.channel().close();
2.异常断开#xff0c;比如客户端挂掉了
服务端定义handler来处理连接断开情况下要进行的逻辑操作#xff1a;
package com.xkj.server.handler;import com.xkj.ser…客户端与服务端断开有两种情况
1.正常断开客户端调用了ctx.channel().close();
2.异常断开比如客户端挂掉了
服务端定义handler来处理连接断开情况下要进行的逻辑操作
package com.xkj.server.handler;import com.xkj.server.session.Session;
import com.xkj.server.session.SessionFactory;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import lombok.extern.slf4j.Slf4j;Slf4j
ChannelHandler.Sharable
public class QuitHandler extends ChannelInboundHandlerAdapter {Overridepublic void channelInactive(ChannelHandlerContext ctx) throws Exception {Session session SessionFactory.getSession();session.unbind(ctx.channel());log.debug({}已经断开了, ctx.channel());}Overridepublic void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {Session session SessionFactory.getSession();session.unbind(ctx.channel());log.debug({}已经异常断开了异常是{}, ctx.channel(), cause.getMessage());}
}