简体   繁体   中英

java.net.BindException: Permission denied as root

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:

However, when I try to run the KnockKnockServer, I get an IOException and then the server prints

Could not listen on port: 4444.

I added a e.printStackTrace() in the IOException catch block, and get:

[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?

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.

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.

I will follow up with the Hands Off support, maybe they can help.

Thanks, Regards Benedikt

我能想到的唯一解释是SELinux拒绝了绑定。

4444 port is used by another program.

go to task manager and process tab check any javaw.exe is running. end the program.then run your program

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM