Is Netty supported on android?

cobe24 qu_en2008 at yahoo.com.cn
Mon Nov 15 20:50:52 EST 2010


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. 
-- 
View this message in context: http://netty-forums-and-mailing-lists.685743.n2.nabble.com/Is-Netty-supported-on-android-tp5742412p5742412.html
Sent from the Netty User Group mailing list archive at Nabble.com.


More information about the netty-users mailing list