java.net.BindException: 权限被拒绝作为 root
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12131673/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
java.net.BindException: Permission denied as root
提问by Benedikt K?ppel
I'm following Oracle's ServerSide Socket tutorial at http://docs.oracle.com/javase/tutorial/networking/sockets/clientServer.html. I use the source as they provide it:
我正在关注http://docs.oracle.com/javase/tutorial/networking/sockets/clientServer.html 上的Oracle 服务器端套接字教程。我使用他们提供的来源:
- http://docs.oracle.com/javase/tutorial/networking/sockets/examples/KnockKnockServer.java
- http://docs.oracle.com/javase/tutorial/networking/sockets/examples/KnockKnockProtocol.java
- http://docs.oracle.com/javase/tutorial/networking/sockets/examples/KnockKnockServer.java
- http://docs.oracle.com/javase/tutorial/networking/sockets/examples/KnockKnockProtocol.java
However, when I try to run the KnockKnockServer, I get an IOException and then the server prints
但是,当我尝试运行 KnockKnockServer 时,我得到一个 IOException,然后服务器打印
Could not listen on port: 4444.
I added a e.printStackTrace()
in the IOException catch block, and get:
我e.printStackTrace()
在 IOException catch 块中添加了一个,并得到:
[beni@mackerel:~]$ \sudo java KnockKnockServer
Creating socket
Could not listen on port: 4444.
java.net.BindException: Permission denied
at java.net.PlainSocketImpl.socketBind(Native Method)
at java.net.PlainSocketImpl.bind(PlainSocketImpl.java:383)
at java.net.ServerSocket.bind(ServerSocket.java:328)
at java.net.ServerSocket.<init>(ServerSocket.java:194)
at java.net.ServerSocket.<init>(ServerSocket.java:106)
at KnockKnockServer.main(KnockKnockServer.java:41)
Notice, I'm running it as root and try to open port 4444. Why do I still get a Permission denied error?
请注意,我以 root 身份运行它并尝试打开端口 4444。为什么我仍然收到 Permission denied 错误?
采纳答案by Benedikt K?ppel
I managed to fix the problem. I had Hands Off! installed on my system, but disabled all rules from the menu bar. The KnockKnockServer still couldn't open the port. Now I have uninstalled Hands Off! completely, and can open ports as usual.
我设法解决了这个问题。我已经放手了!安装在我的系统上,但禁用了菜单栏中的所有规则。KnockKnockServer 仍然无法打开端口。现在我已经卸载了 Hands Off!完全,并且可以像往常一样打开端口。
It is still a bit surprising, because I was always able to open the same socket port with nc -l 4444
and with a C program, but not from Java. But at the same time, Hands Off didn't ask me if I want to allow my KnockKnockServer to open a port.
这仍然有点令人惊讶,因为我总是能够nc -l 4444
用 C 程序打开同一个套接字端口,但不能从 Java打开。但与此同时,Hands Off 并没有问我是否允许我的 KnockKnockServer 打开一个端口。
I will follow up with the Hands Off support, maybe they can help.
我会跟进 Hands Off 支持,也许他们可以提供帮助。
Thanks, Regards Benedikt
谢谢,问候本尼迪克特
回答by Stephen C
The only explanation that I can think of is that the bind is being denied by SELinux.
我能想到的唯一解释是 SELinux 拒绝了绑定。
回答by Mohammod Hossain
4444 port is used by another program.
4444 端口被另一个程序使用。
go to task manager and process tab check any javaw.exe is running. end the program.then run your program
转到任务管理器和进程选项卡,检查是否有任何 javaw.exe 正在运行。结束程序。然后运行你的程序