Is Netty supported on android?
Johnny Luong
johnny.luong at trustcommerce.com
Mon Nov 15 21:49:43 EST 2010
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 11/15/2010 05:50 PM, cobe24 wrote:
> Hi,
>
> I'm trying to use Netty to write a server app on android, but the port
> binding always fails.
> The Internet permission has been turned on in AndroidManifest.xml like:
>
> <uses-permission android:name="android.permission.INTERNET" />
>
>
> The code is like below:
>
> int portNum = 25336;
> if(arguments.containsKey("port")) {
> String portString = arguments.getString("port");
> portNum = Integer.parseInt(portString);
> }
>
> bootstrap = new ServerBootstrap(new NioServerSocketChannelFactory(
> Executors.newCachedThreadPool(), Executors
> .newCachedThreadPool()));
>
> bootstrap.setOption("keepAlive", true);
> bootstrap.setOption("child.tcpNoDelay", true);
> bootstrap.setOption("child.keepAlive", true);
> bootstrap.setOption("child.reuseAddress", true);
> bootstrap.setOption("child.connectTimeoutMillis", 100);
> bootstrap.setOption("readWriteFair", true);
>
> // channel group is used for closing connection properly
> channelGroup = new DefaultChannelGroup();
>
> // Configure the pipeline factory.
> ServerPipelineFactory pipelineFactory = new ServerPipelineFactory();
> pipelineFactory.setInstrumentation(this);
> bootstrap.setPipelineFactory(pipelineFactory);
> Log.d(TAG, "Configured server pipline factory");
>
> // NOTE: This is a work around to prevent the bad address error.
> // This was a bug exposed on Android 2.2
> // http://code.google.com/p/android/issues/detail?id=9431
> System.setProperty("java.net.preferIPv6Addresses", "false");
>
> // Bind and start to accept incoming connections.
> Channel channel = null;
> try{
> //byte ip[] = new byte[] { 10, 0, 2, 15};
> //InetAddress address1 = InetAddress.getByAddress(ip);
>
> channel = bootstrap.bind(new
> InetSocketAddress(InetAddress.getLocalHost(), portNum));
> }
> catch(ChannelException e){
> Log.e(TAG, "ChannelException "+e.getMessage()+"at port: "+portNum);
> }
>
> .
> If I run the above code on a real android device, it always throws an
> exception "Failed to open a server socket".
> Fearing that this port 25336 could already be used by another app on the
> device, I've also tried other ports bigger than 1024, but the problem is
> still there.
> I tried the code above on both HTC Dream and Motorola Milestone, but no
> luck.
>
> If anyone could provide me some suggestion, that would be really great.
> Thanks very much.
Hmmm, last I heard it worked well on Android. Are you able to bind the
endpoint without the Netty abstraction using a ServerSocket?
Best,
Johnny
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/
iEYEARECAAYFAkzh8UQACgkQg7TIS7A9isf5cwCgsanWyp4G6grFO1FBRfQSj+b5
8eEAoL6i4mzvVCB/slTbiXF9qQkebiMf
=wPoV
-----END PGP SIGNATURE-----
More information about the netty-users
mailing list