读书人

关于netty的不解

发布时间: 2012-07-15 20:20:06 作者: rapoo

关于netty的疑惑
应用场景为 android中使用netty,android关闭无线、gprs,然后随便连接一个ip地址,部分代码

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()来判断是否连接成功。

读书人网 >开源软件

热点推荐