使用wAsync(大气)的android websocket连接超时

时间:2013-04-24 07:09:39

标签: android android-emulator websocket netty atmosphere

我以前写过一个基于wAsync的Java SE客户端。它与版本1.0.RC1连接到Atmosphere 1.1.RC1是坚如磐石的。我按照Jeanfrancois的这个例子来完成this task

一切正常,JSON编码,订阅,广播以及向URI发送POST。好到目前为止。

但是,将此示例放到Android中会在尝试订阅资源时引发超时异常。正如您在日志中看到的,我想在

上打开一个套接字
http://localhost:8080/resource/playerpool

同样,这在Java SE 6客户端上运行良好。

任何人都知道为什么这会在Android模拟器上遇到超时,而是来自Java SE客户端的确切代码?

我确实在AndroidManifest.xml中设置了权限

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

在Android日志下方,尝试打开套接字上的连接时。

04-24 06:27:41.043: W/System.err(1512): java.net.ConnectException: connection timed out to ws://localhost:8080/resource/playerpool?X-Atmosphere-Transport=long-polling&X-atmo-protocol=true&X-Atmosphere-tracking-id=0&X-Atmosphere-Framework=1.0&X-Cache-Date=0
04-24 06:27:41.051: W/System.err(1512):     at com.ning.http.client.providers.netty.NettyConnectListener.operationComplete(NettyConnectListener.java:103)
04-24 06:27:41.051: W/System.err(1512):     at org.jboss.netty.channel.DefaultChannelFuture.notifyListener(DefaultChannelFuture.java:427)
04-24 06:27:41.051: W/System.err(1512):     at org.jboss.netty.channel.DefaultChannelFuture.notifyListeners(DefaultChannelFuture.java:418)
04-24 06:27:41.051: W/System.err(1512):     at org.jboss.netty.channel.DefaultChannelFuture.setFailure(DefaultChannelFuture.java:380)
04-24 06:27:41.051: W/System.err(1512):     at org.jboss.netty.channel.socket.nio.NioClientBoss.processConnectTimeout(NioClientBoss.java:139)
04-24 06:27:41.051: W/System.err(1512):     at org.jboss.netty.channel.socket.nio.NioClientBoss.process(NioClientBoss.java:82)
04-24 06:27:41.051: W/System.err(1512):     at org.jboss.netty.channel.socket.nio.AbstractNioSelector.run(AbstractNioSelector.java:312)
04-24 06:27:41.051: W/System.err(1512):     at org.jboss.netty.channel.socket.nio.NioClientBoss.run(NioClientBoss.java:41)
04-24 06:27:41.051: W/System.err(1512):     at org.jboss.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable.java:108)
04-24 06:27:41.051: W/System.err(1512):     at org.jboss.netty.util.internal.DeadLockProofWorker$1.run(DeadLockProofWorker.java:42)
04-24 06:27:41.051: W/System.err(1512):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
04-24 06:27:41.051: W/System.err(1512):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
04-24 06:27:41.051: W/System.err(1512):     at java.lang.Thread.run(Thread.java:856)
04-24 06:27:41.051: W/System.err(1512): Caused by: java.net.ConnectException: connection timed out
04-24 06:27:41.051: W/System.err(1512):     at org.jboss.netty.channel.socket.nio.NioClientBoss.processConnectTimeout(NioClientBoss.java:136)
04-24 06:27:41.051: W/System.err(1512):     ... 8 more
04-24 06:27:41.063: W/System.err(1512): java.util.concurrent.ExecutionException: java.net.ConnectException: connection timed out to ws://localhost:8080/rest-group-e/playerpool?X-Atmosphere-Transport=long-polling&X-atmo-protocol=true&X-Atmosphere-tracking-id=0&X-Atmosphere-Framework=1.0&X-Cache-Date=0
04-24 06:27:41.063: W/System.err(1512):     at com.ning.http.client.providers.netty.NettyResponseFuture.abort(NettyResponseFuture.java:327)
04-24 06:27:41.063: W/System.err(1512):     at com.ning.http.client.providers.netty.NettyConnectListener.operationComplete(NettyConnectListener.java:107)
04-24 06:27:41.063: W/System.err(1512):     at org.jboss.netty.channel.DefaultChannelFuture.notifyListener(DefaultChannelFuture.java:427)
04-24 06:27:41.074: W/System.err(1512):     at org.jboss.netty.channel.DefaultChannelFuture.notifyListeners(DefaultChannelFuture.java:418)
04-24 06:27:41.074: W/System.err(1512):     at org.jboss.netty.channel.DefaultChannelFuture.setFailure(DefaultChannelFuture.java:380)
04-24 06:27:41.074: W/System.err(1512):     at org.jboss.netty.channel.socket.nio.NioClientBoss.processConnectTimeout(NioClientBoss.java:139)
04-24 06:27:41.074: W/System.err(1512):     at org.jboss.netty.channel.socket.nio.NioClientBoss.process(NioClientBoss.java:82)
04-24 06:27:41.074: W/System.err(1512):     at org.jboss.netty.channel.socket.nio.AbstractNioSelector.run(AbstractNioSelector.java:312)
04-24 06:27:41.074: W/System.err(1512):     at org.jboss.netty.channel.socket.nio.NioClientBoss.run(NioClientBoss.java:41)
04-24 06:27:41.074: W/System.err(1512):     at org.jboss.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable.java:108)
04-24 06:27:41.083: W/System.err(1512):     at org.jboss.netty.util.internal.DeadLockProofWorker$1.run(DeadLockProofWorker.java:42)
04-24 06:27:41.083: W/System.err(1512):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
04-24 06:27:41.083: W/System.err(1512):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
04-24 06:27:41.083: W/System.err(1512):     at java.lang.Thread.run(Thread.java:856)
04-24 06:27:41.083: W/System.err(1512): Caused by: java.net.ConnectException: connection timed out to ws://localhost:8080/rest-group-e/playerpool?X-Atmosphere-Transport=long-polling&X-atmo-protocol=true&X-Atmosphere-tracking-id=0&X-Atmosphere-Framework=1.0&X-Cache-Date=0
04-24 06:27:41.083: W/System.err(1512):     at com.ning.http.client.providers.netty.NettyConnectListener.operationComplete(NettyConnectListener.java:103)
04-24 06:27:41.083: W/System.err(1512):     ... 12 more
04-24 06:27:41.083: W/System.err(1512): Caused by: java.net.ConnectException: connection timed out
04-24 06:27:41.083: W/System.err(1512):     at org.jboss.netty.channel.socket.nio.NioClientBoss.processConnectTimeout(NioClientBoss.java:136)
04-24 06:27:41.083: W/System.err(1512):     at org.jboss.netty.channel.socket.nio.NioClientBoss.process(NioClientBoss.java:82)
04-24 06:27:41.083: W/System.err(1512):     at org.jboss.netty.channel.socket.nio.AbstractNioSelector.run(AbstractNioSelector.java:312)
04-24 06:27:41.083: W/System.err(1512):     at org.jboss.netty.channel.socket.nio.NioClientBoss.run(NioClientBoss.java:41)
04-24 06:27:41.083: W/System.err(1512):     ... 3 more

1 个答案:

答案 0 :(得分:1)

http://localhost:8080/resource/playerpool

在Android模拟器/设备中,此URL将尝试连接到模拟器/设备本身上运行的HTTP服务器,除非您有另一个Android应用程序作为在其上运行的HTTP服务器,否则这可能不存在。

您的Web服务是否在模拟器的主机上运行?尝试将localhost替换为10.0.2.2。在模拟器中,此IP根据Android Emulator documentation

指向您的主机