commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject RE: httpclient hangs indefinately
Date Thu, 31 Jan 2002 18:23:47 GMT
Well, since the method creates a new Socket object, it is subject
to the behavior of the Socket class.  Unfortunately, at least as of 1.3,
attempting to create a new Socket to a host/port combo that does not answer
blocks indefinately (or at least for a very long time), this can't be
avoided directly.  (It would be really nice if the JDK provided a Socket
constructor that took a timeout value to pass to the underlying OS).  The
three ways I can think of to avoid it off hand are:

	1. Implement a timeout mechanism outside of HttpClient with a
seperate thread that interrupts the connection attempts.
	2. Implement a Socket object in the HttpClient framework that uses
this same sort of mechanism but hides the details behind the API
	3. Use the 1.4 JDK and upgrade everything to use the new channels
API in non-blocking mode.

I wish there were a cleaner way.  If anyone knows of one I'd love to hear


-----Original Message-----
From: Allen, Michael B (RSCH) []
Sent: Wednesday, January 30, 2002 10:50 PM
To: ''
Subject: httpclient hangs indefinately

If I just use a simple test program like below and try to connect to certain
IP addresses that
are routable but don't have anything listing at the other end (returns
nothing, dead air), the
client hangs indefinately. Can anyone think of a solution to this problem?


import org.apache.commons.httpclient.*;

public class Test {

        public static void main(String[] argv) throws Exception {
                HttpConnection con = new HttpConnection( argv[0],
Integer.parseInt( argv[1] ));
                con.printLine( "GET /index.html HTTP/1.0" );
                String s;
                while(( s = con.readLine() ) != null ) {
                        System.out.println( s );

To unsubscribe, e-mail:
For additional commands, e-mail:

To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message