public class TextWebSocketFrameHandler extends SimpleChannelInboundHandler{
@Override
public void handlerRemoved(ChannelHandlerContext ctx) throws Exception {
......//此处对断网进行了处理
}
}
这种方法可以识别浏览器断开的情况,但是网络断开识别不了。然后同事说,linux可以配置网络,试了试。sysctl.conf文件里面设置:
net.ipv4.tcp_keepalive_time = 10
net.ipv4.tcp_keepalive_probes = 2
net.ipv4.tcp_keepalive_intvl = 2
转发自:https://blog.youkuaiyun.com/ljlx8023/article/details/72876678