0

我之前写过一个基于 wAsync 的 Java SE 客户端。它与连接到 Atmosphere 1.1.RC1 的 1.0.RC1 版本非常稳定。我按照 Jeanfrancois 的这个例子来完成这个任务

一切正常,JSON 编码、订阅、广播和发送 POST 到 URI。目前很好。

但是,将此示例放到 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
4

1 回答 1

1

http://localhost:8080/resource/playerpool

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

您的 Web 服务是否在模拟器的主机上运行?尝试替换localhost10.0.2.2. 根据Android Emulator 文档,在模拟器中,此 IP 指的是您的主机

于 2013-04-24T07:25:03.590 回答