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?
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 4444and 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