nettyの疑惑について

2399 ワード

アプリケーションシーンはandroidでnettyを使用し、androidは無線、gprsをオフにし、ipアドレス、一部のコードを任意に接続します.

bootstrap.setOption("keepAlive", true);
bootstrap.setOption("tcpNoDelay", true);
bootstrap.setOption("connectTimeoutMillis", CONNECT_TIMEOUT);

//            
ChannelFuture connectFuture = bootstrap.connect(inetSocketAddress);

session = connectFuture.awaitUninterruptibly().getChannel();

Log.i("re", "connectFuture.isSuccess()=" + connectFuture.isSuccess());
Log.i("re", "connectFuture.isConnected()=" + session.isConnected());
if (session.isConnected()) {
	businessListener.onServerConnected();
} else {
	businessListener.onServerNetWorkError();
}

なんてことだisConnected()はtrueです.
ワイヤレスまたはgprsをオンにすると、正常になります.なぜ誰もネットワークを持っていない場合にsessionしますか.isConnected()はtrueですか?
handlerコード

private class MinaClientHandler extends SimpleChannelHandler {

		@Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
			String theMessage = (String) e.getMessage();
			JSONObject commandJsonObject = new JSONObject(theMessage);
			businessListener.onReceive(commandJsonObject);
		}

public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
			Log.i("re", "channelConnected");
		}

		@Override
		public void channelDisconnected(ChannelHandlerContext ctx, ChannelStateEvent e) {
			Log.i("re", "channelDisconnected");
		}

		@Override
		public void channelClosed(ChannelHandlerContext ctx, ChannelStateEvent e) {
			Log.i("re", "channelClosed");
		}

		public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception {
			Throwable cause = e.getCause();
			cause.printStackTrace();
			// if (cause instanceof SocketException) {
			// ctx.getChannel().close();
			// }
			Log.i("re", "exceptionCaught");
		}
	}

ネットワークがない場合、handlerのchannelConnected channelDisconneted channelClosedが正常に呼び出され、nettyがなぜこのように処理するのか分からないため、ネットワークがない場合、sessionを通過できない.isConnected()は、接続が成功したかどうかを判断します.