java.net.BindException: Permission denied as root
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
Benedikt Köppel
I'm the Founder and CTO of Locatee. We help large organizations optimize their workspace with big data technology. Learn more here https://www.locatee.ch/video. We are hiring! If you are skilled in Java, Spring, Hibernate, Data Science, JavaScript or AngularJS, please shoot me a line.
Updated on June 04, 2022Comments
-
Benedikt Köppel almost 2 years
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/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
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?
-
Benedikt Köppel over 11 yearsNo, the port is not in use.
netstat -a | grep 4444
returns nothing. -
Benedikt Köppel over 11 yearsI run this on Mac OS X 10.7.4. I am not aware that there is SELinux here.
-
user207421 over 11 yearsIf the port was in use you would get a different exception message.