1
我的代碼如下所示:com.sun.net.httpserver錯誤,是什麼意思?
import com.sun.net.httpserver.*;
import java.net.InetSocketAddress;
...
void Srart_Server()
{
....
InetSocketAddress addr=new InetSocketAddress(80);
HttpServer server=HttpServer.create(addr,0); // Line : 32
它跑在我的電腦就OK了,但在我抄應用到Linux和運行它,我得到了以下錯誤:
java.net.SocketException: Permission denied
at sun.nio.ch.Net.bind0(Native Method)
at sun.nio.ch.Net.bind(Net.java:433)
at sun.nio.ch.Net.bind(Net.java:425)
at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:223)
at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74)
at sun.net.httpserver.ServerImpl.<init>(ServerImpl.java:100)
at sun.net.httpserver.HttpServerImpl.<init>(HttpServerImpl.java:50)
at sun.net.httpserver.DefaultHttpServerProvider.createHttpServer(DefaultHttpServerProvider.java:35)
at com.sun.net.httpserver.HttpServer.create(HttpServer.java:130)
at Http_Server.Srart_Server(Http_Server.java:32)
爲什麼?如何解決這個問題?
很可能您嘗試啓動服務器的端口已被佔用。嘗試使用不太受歡迎的端口--8080或8888 –
在這種情況下,錯誤消息將顯示爲:「地址已在使用中」。 –