我遇到了这种奇怪的情况,我可以使用本地IP地址绑定ServerBootstrap,但是当我尝试使用我的公共IP地址时,它会引发异常:Exception in thread "main" org.jboss.netty.channel.ChannelException: Failed to bind to: /57.88.173.132:5055
我改变了地址并不是真实的,他们是随机数,但是 港口是真正的一个
这是代码
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));
这是抛出的异常
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)