4

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)
Pendexos Eimai
  • 63
  • 1
  • 1
  • 4

1 Answers1

3

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.

Community
  • 1
  • 1
Maksym
  • 4,434
  • 4
  • 27
  • 46
  • i checked hosts file local host is 127.0.0.1,what do you mean by: i need to use the correct address for one of my network interfaces my public ip isn't correct?i'm confused,i have to add to hosts file my public ip and name it? or what? – Pendexos Eimai Dec 02 '14 at 18:35
  • I have edited my answer, 127.0.0.1 should be fine, seems like your issue quite simple -> port 5055 alredy in use by other process on your server. – Maksym Dec 02 '14 at 20:03
  • I already checcked that my port is unique.server binds with 0.0.0.0 but I can't understand how is that possible :/ can someone explain to me like I was five :) ?? – Pendexos Eimai Dec 02 '14 at 23:11
  • 0.0.0.0 instructs Netty to bind to all available interfaces. The kernel will automatically detect all available network interfaces and, if possible, bind to them all on the chosen port. You will be able to connect to Netty by any of the available IP addresses. As already mentioned by others 'netstat -l | grep 5055' will show if anything is already listening on the port. I would also double check the available IP addresses using either 'ifconfig' or 'ip addr' – johnstlr Dec 04 '14 at 09:24