Wrapper.exe与ServerSocket

时间:2012-09-20 06:09:51

标签: java java-ee network-programming

最初我在WildCard地址0.0.0.0中占用了端口80 现在我试图将这个端口80绑定在一个可用的ipaddress中,如172.18.81.56

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();  
    }  

1 个答案:

答案 0 :(得分:0)

你不能绑定到172.18.81.56:80,除非(a)没有其他人绑定到172.18.81.56:80并且(b)没有其他人绑定到0.0.0.0:80.