我在http://docs.oracle.com/javase/tutorial/networking/sockets/clientServer.html关注 Oracle 的 ServerSide Socket 教程。我使用他们提供的来源:
- http://docs.oracle.com/javase/tutorial/networking/sockets/examples/KnockKnockServer.java
- http://docs.oracle.com/javase/tutorial/networking/sockets/examples/KnockKnockProtocol.java
但是,当我尝试运行 KnockKnockServer 时,我得到一个 IOException 然后服务器打印
Could not listen on port: 4444.
我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)
请注意,我以 root 身份运行它并尝试打开端口 4444。为什么我仍然收到 Permission denied 错误?