I previously wrote a Java SE client based on wAsync. It works rock-solid with version 1.0.RC1 connected to Atmosphere 1.1.RC1. I followed this example from Jeanfrancois to accomplish this task
Everything works, JSON encoding, subscribing, broadcasting and sending a POST to a URI. Good so far.
However, putting this example to Android would raise a timeout exception when trying to subscribe to a resource. As you can see in the log, I wanted to open a socket on
http://localhost:8080/resource/playerpool
Again, this worked fine on the Java SE 6 client.
Anyone has a clue why this would run into a timeout on the Android emulator while being the exact code from the Java SE client?
I did set the permission in the AndroidManifest.xml
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
Below the Android log, when trying to open the connection on the socket.
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
http://localhost:8080/resource/playerpool
In the Android emulator/device, this URL will try to connect to an HTTP server running on the emulator/device itself, which probably doesn't exist unless you've another Android app acting as a HTTP server running on it.
Is your web service running on the host machine of the emulator? Try replacing localhost
with 10.0.2.2
. In the emulator this IP refers to your host machine according to Android Emulator documentation