java.net.BindException : Address already in use (Bind failed) but port is only used once

标签 java sockets debugging server

网上查了一下,当端口已经在使用时,会出现BindException。但我只使用过这个端口号一次。这是我的代码。

public class ServerUI extends Application {
    private ServerSocket serverSocket = null;

    public ServerUI() throws IOException {
        this.serverSocket = new ServerSocket(1111);
    }

    @Override
    public void start(Stage primaryStage) throws Exception {
        ServerUI server = new ServerUI();

        FXMLLoader loader = new FXMLLoader(getClass().getResource("sample.fxml"));
        Parent root = (Parent)loader.load();

        Controller controller = (Controller)loader.getController();

        primaryStage.setTitle("Server");
        primaryStage.setScene(new Scene(root, 300, 275));
        primaryStage.show();
    }

    public static void main(String[] args) {launch(args);}
}

根据堆栈跟踪,当我尝试在第 10 行创建 ServerUI 实例时,错误发生在第 5 行。不知道如何调试这个。感谢帮助。

最佳答案

要释放 Windows 计算机上的端口,请以管理员身份运行命令提示符并执行以下命令:

netstat -o -n -a | findstr 0.0:1111 // finds the process using the port
taskkill /F /PID 10880 // change 10880 with your PID number which you can see from the previous command.

关于java.net.BindException : Address already in use (Bind failed) but port is only used once,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43009139/

相关文章:

java - JAVA项目中如何获取文件绝对路径

java - 如何在 Processing 中从网络摄像头捕获带音频的视频

c++ - connect() 函数停止程序

debugging - : "JDI Event Dispatch" java. lang.NullPointerException 期间发生内部错误

debugging - 如何调试 Electron.NET 应用程序

java - TextView 不在主屏幕上打印字符串

java - 调用从基类 : use this , super 继承的方法或隐式调用的最佳方法

python - 向python服务器添加超时时出现非阻塞错误

android - Android中的套接字以连接到数据库

java - Eclipse Helios 忽略断点