最近在android上做的一个简单的netty客户端,基本上是按照官网上的例子来做的
http://netty.io/4.1/xref/io/netty/example/securechat/package-summary.htmlChatClient:
            final SslContext sslCtx = SslContextBuilder.forClient().trustManager(InsecureTrustManagerFactory.INSTANCE).build();
            bootstrap  = new Bootstrap()
                    .group(group)
                    .channel(NioSocketChannel.class)
                    .handler(new SecureChatClientInitializer(sslCtx,user_code));            bootstrap.option(ChannelOption.SO_KEEPALIVE,true);
            bootstrap.option(ChannelOption.TCP_NODELAY,true);
            bootstrap.option(ChannelOption.SO_TIMEOUT, 5000);            cf = bootstrap.connect(new InetSocketAddress(HOST, PORT));SecureChatClientInitializer:
      pipeline.addLast(sslCtx.newHandler(ch.alloc(), HOST, PORT));        // On top of the SSL handler, add the text line codec.
        pipeline.addLast(new DelimiterBasedFrameDecoder(8192, Delimiters.lineDelimiter()));
        pipeline.addLast(new StringDecoder());
        pipeline.addLast(new StringEncoder());
        pipeline.addLast("ping", new IdleStateHandler(5, 5, 5 * 3, TimeUnit.SECONDS));        // and then business logic.
        pipeline.addLast(new SecureChatClientHandler(usercode));SecureChatClientHandler:    public void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception {
        System.err.println(msg);
    }    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
        cause.printStackTrace();
        ctx.close();
    }netty客户端写在service里面,诡异的是app页面保持活动的时候接收和发送消息都正常,用usb线连在电脑调试的时候也正常,一旦拔掉调试线,并把APP放在后台运行的时候,过大概40s左右的时间服务器就会出现连接丢失的情况,重新连上后可以重连,并报这样的错误  java.io.IOException: Software caused connection abort可以确定的是service一直是在运行没有被杀掉,但为什么会出现这么奇怪的事情,连接上调试线和没连上具体有什么区别?
求大侠告知