Why Netty doesn’t bind with public IP address & it binds with 127.0.0.1

bindnettynullreferenceexceptionpublicserver

i got in this weird situation and i can bind ServerBootstrap with local IP address but when i tried with my public IP address it throws an exception : Exception in thread "main" org.jboss.netty.channel.ChannelException: Failed to bind to: /57.88.173.132:5055

can someone explain to me what is wrong??? btw im using netty 3.6.1

i changed the address its not real they are random numbers but the
port is real one

here is the code

private static final String BIND_ADDRESS = "57.88.173.132";
private static final int PORT = 5055;

public Server()
{
    try
    {
        startup();
    }
    catch (IOException e)
    {
        e.printStackTrace();
    }
}
private void startup() throws IOException
{
    ServerBootstrap serBootstrap = new ServerBootstrap(new NioServerSocketChannelFactory(Executors.newCachedThreadPool(),Executors.newCachedThreadPool())); 
    serBootstrap.setPipelineFactory(new PipelineFactory());
    serBootstrap.bind(new InetSocketAddress(BIND_ADDRESS,PORT));

here is the exception thrown

Exception in thread "main" org.jboss.netty.channel.ChannelException: Failed to bind to: /57.88.173.132:5055
    at org.jboss.netty.bootstrap.ServerBootstrap.bind(ServerBootstrap.java:301)
    at com.game.server.Server.startup(Server.java:33)
    at com.game.server.Server.<init>(Server.java:22)
    at com.game.server.Server.main(Server.java:44)
Caused by: java.net.BindException: Cannot assign requested address: bind
    at sun.nio.ch.Net.bind0(Native Method)
    at sun.nio.ch.Net.bind(Unknown Source)
    at sun.nio.ch.Net.bind(Unknown Source)
    at sun.nio.ch.ServerSocketChannelImpl.bind(Unknown Source)
    at sun.nio.ch.ServerSocketAdaptor.bind(Unknown Source)
    at org.jboss.netty.channel.socket.nio.NioServerBoss$RegisterTask.run(NioServerBoss.java:193)
    at org.jboss.netty.channel.socket.nio.AbstractNioSelector.processTaskQueue(AbstractNioSelector.java:367)
    at org.jboss.netty.channel.socket.nio.AbstractNioSelector.run(AbstractNioSelector.java:291)
    at org.jboss.netty.channel.socket.nio.NioServerBoss.run(NioServerBoss.java:42)
    at org.jboss.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable.java:108)
    at org.jboss.netty.util.internal.DeadLockProofWorker$1.run(DeadLockProofWorker.java:42)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

Best Answer

This actually not a netty issue.

That's clear java.net.BindException. For most cases it means that this port already listening by some other process, to detect it you can use netstat command.

But there are few special cases:

Note 1 from here:

It may be related to a misconfiguration in your /etc/hosts. In my case, it was like this: 192.168.1.11 localhost instead of 127.0.0.1 localhost

Note 2 from here:

The error says Cannot assign requested address. This means that you need to use the correct address for one of your network interfaces or 0.0.0.0 to accept connections from all interfaces.

edited.