zoukankan      html  css  js  c++  java
  • netty4 断线重连

    监听到连接服务器失败时,会在3秒后重新连接(执行doConnect方法)

    这还不够,当客户端掉线时要进行重新连接

    在我们自己定义逻辑处理的Handler中

    @Override
        public void channelInactive(ChannelHandlerContext ctx) throws Exception {
            Log.d(Config.TAG, "与服务器断开连接服务器");
            super.channelInactive(ctx);
            MsgHandle.getInstance().channel = null;
    
            //重新连接服务器
            ctx.channel().eventLoop().schedule(new Runnable() {
                @Override
                public void run() {
                    MyClient.doConnect();
                }
            }, 2, TimeUnit.SECONDS);
            ctx.close();
        }
  • 相关阅读:
    vue
    vue
    vue
    vue
    vue
    vue
    vue
    vue
    vue
    vue
  • 原文地址:https://www.cnblogs.com/zhengtu2015/p/7447255.html
Copyright © 2011-2022 走看看