hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Erxiang Liu <erxi...@us.ibm.com>
Subject Re: java.net.BindException on windows vista
Date Thu, 29 Mar 2007 18:38:00 GMT

Roland:

we have the test code that simply open a connection, If it is using the
default JVM http url handler , it works fine. But if we use or our
customized http url handler, which calls the apache http client code, it
would fail with the trace like this.
Fatal transport error: Address already in use: NET_Bind
java.net.BindException: Address already in use: NET_Bind
        at java.net.PlainSocketImpl.bind(PlainSocketImpl.java:398)
        at java.net.Socket.bind(Socket.java:587)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:64)
        at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:615)
        at
org.apache.commons.httpclient.protocol.ReflectionSocketFactory.create
Socket(ReflectionSocketFactory.java:138)
        at
org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory.c
reateSocket(DefaultProtocolSocketFactory.java:124)
        at
org.apache.commons.httpclient.HttpConnection.open(HttpConnection.java
:706)
        at
org.apache.commons.httpclient.MultiThreadedHttpConnectionManager$Http
ConnectionAdapter.open(MultiThreadedHttpConnectionManager.java:1321)
        at
org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(Htt
pMethodDirector.java:386)
        at
org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMe
thodDirector.java:170)
        at
org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.jav
a:396)

the test code looks like this :
            request_url = new URL("http://www.oreilly.com");
            HttpURLConnection hcon = (HttpURLConnection)
request_url.openConnection();
            int result = hcon.getResponseCode();
I also wrote the code use apache client directly and it also causes the
same exception.

this made me think this may be an apache bug.  The wield thing is we can
only recreate this problem in some of vista machines, but not all vista
machines. And it works fine on windows XP. Could this be an apache bug? if
so, what is the process to open an apache bug?

Also, is there anyway to tune the system settings instead of changing the
code as you recommended below to solve this problem?


thanks,

Michell:



                                                                           
             Roland Weber                                                  
             <http-async@dubio                                             
             so.net>                                                    To 
                                       HttpClient User Discussion          
             03/19/2007 02:20          <httpclient-user@jakarta.apache.org 
             PM                        >                                   
                                                                        cc 
                                                                           
             Please respond to                                     Subject 
             "HttpClient User          Re: java.net.BindException on       
                Discussion"            windows vista                       
             <httpclient-user@                                             
             jakarta.apache.or                                             
                    g>                                                     
                                                                           
                                                                           
                                                                           




Hi Michelle,

> I think you are right.  the apache httpclient code seems  hardcoded the
> local port to 0 when creating a socket. Sounds like this should not be a
> vista specific issue.

Port 0 is never used as a port number. Specifying 0 indicates to the OS
that any free port is acceptable. Looks like Vista, or the JVM on Vista,
doesn't know which ports are free.
>
> This depends on some low level settings related to address re-use.
>
> just wonder how you find those low level settings and maybe change it and
> make it working?

try this one:
http://java.sun.com/j2se/1.4.2
/docs/api/java/net/Socket.html#setReuseAddress(boolean)

Create a custom ProtocolSocketFactory to contain the modified code:
http://jakarta.apache.org/commons/httpclient/apidocs/org/apache/commons/httpclient/protocol/ProtocolSocketFactory.html


It needs to be registered for Protocol "http":
http://jakarta.apache.org/commons/httpclient/apidocs/org/apache/commons/httpclient/protocol/Protocol.html#registerProtocol(java.lang.String,%20org.apache.commons.httpclient.protocol.Protocol)



hope that helps,
  Roland

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org


Mime
  • Unnamed multipart/related (inline, None, 0 bytes)
View raw message