关于netty的疑惑
应用场景为 android中使用netty,android关闭无线、gprs,然后随便连接一个ip地址,部分代码
竟然 session.isConnected()为true。
打开无线或者gprs,就变得正常,为什么在没人任何网络的情况下session.isConnected()为true呢?
handler代码private class MinaClientHandler extends SimpleChannelHandler {@Overridepublic 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");}@Overridepublic void channelDisconnected(ChannelHandlerContext ctx, ChannelStateEvent e) {Log.i("re", "channelDisconnected");}@Overridepublic 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 channelDisconnected channelClosed 正常调用,不明白netty为什么这样处理,这样就造成当没有任何网络的的情况下,就不能通过session.isConnected()来判断是否连接成功。