2012-09-20 22 views
0

起初我已經在通配符地址佔用的端口80 0.0.0.0
現在我想這個端口綁定80中可用的一個ip地址說172.18.81.56Wrapper.exe VS ServerSocket的

The following exception occurred 
    java.net.BindException: Address already in use: JVM_Bind 
      at java.net.PlainSocketImpl.socketBind(Native Method) 
      at java.net.PlainSocketImpl.bind(Unknown Source) 
      at java.net.ServerSocket.bind(Unknown Source) 
      at java.net.ServerSocket.<init>(Unknown Source) 

但同時從Windows服務(wrapper.exe)沒有異常,成功創建服務器套接字,可能是什麼問題,執行相同的代碼...

here the piece of code 

    ServerSocket ss = null; 
    try 
    { 
     serverHost = "172.18.81.56"; 
     InetAddress ina = InetAddress.getByName(serverHost); 
     ss = new ServerSocket(port, 10, ina); 
     ss.close(); 
    } 
    catch(Exception e) 
    { 
     e.printStackTrace(); 
    } 

回答

0

您不能綁定到172.18.81.56:80除非(a)沒有其他人必須遵守172.18.81 .56:80和(b)沒有人綁定到0.0.0.0:80。

+0

我可以綁定172.18.81.56:80當上面提到的代碼從Windows服務執行,甚至另一個應用程序與0.0.0.0:80綁定,但不能綁定相同時,在窗口中執行相同的代碼形式cmd提示。 – mreaevnia