我一直遇到这个错误:“新 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);
}
}