java.net.BindException:JVM绑定

时间:2012-10-14 21:37:08

标签: java sockets jvm

我一直遇到这个错误: “新ServerSocket上的异常:java.net.BindException:无法分配请求的地址:JVM_Bind”。 我已经尝试使用netstat来确保端口(1500)上没有运行任何东西。有什么建议吗?

package server;

import java.io.IOException
import java.net.InetAddress
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;
public class Server 
{
private ServerSocket serverSocket;

Server(int Port)
{   
/* create socket server and wait for connection requests */
try 
{
        serverSocket = new ServerSocket(1500, 0, InetAddress.getByName("69.61.210.196"));
        System.out.println("Server waiting for client on port " + serverSocket.getLocalPort());
        while(true) 
        {
    Socket socket = serverSocket.accept();  // accept connection
    System.out.println("New client asked for a connection");
        }
    }
    catch (IOException e) 
    {
        System.out.println("Exception on new ServerSocket: " + e);
    }
}

    public static void main(String[] args) 
    {
       new Server(1500);
    }
}

1 个答案:

答案 0 :(得分:1)

听起来您尝试绑定的IP地址是网络的外部IP地址,而不是您的计算机IP。

建议尝试绑定到127.0.0.10.0.0.0

要在Windows ipconfig和Linux ifconfig上从命令行使用您的计算机IP。