You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Eric Johnson <ej...@yahoo.com> on 2003/02/12 16:00:57 UTC

httpclient and persistant socket connection

Hello!

I seem to be having some trouble with keeping my
socket connection open and
re-using it for several request-response exchanges. If
anyone has any ideas
about how to do this or whether or not it's even
possible please let me
know. I do realize it has only recently reached
alpha2.  Here's a condensed
version of my code:

      HttpConnection conn = new
HttpConnection("127.0.0.1", 8080);
      conn.open();
      HttpMethod get = new GetMethod();
      HttpState state = new HttpState();
      get.setRequestHeader("Connection",
"keep-alive");
      get.setRequestHeader("keep-alive", "3000");
      int respCode = get.execute(state,  conn);
      get.getResponseBodyAsString();
      get.releaseConnection();
      // I just do this so I have an opportunity to
monitor the connections
on my machine
      Thread.sleep(10000);

      get = new GetMethod();
      get.setPath("/home/login/login.jsp/");
      get.setRequestHeader("Connection",
"keep-alive");
      get.setRequestHeader("keep-alive", "3000");
      respCode = get.execute(state,  conn);
      Thread.sleep(10000);

After cranking up the loggin I noticed an exception
was getting masked on
the secodn attempt to execute a get:

2003/02/12 08:54:14:959 CST [TRACE] HttpConnection -
-enter
HttpConnection.write(byte[], int, int)
java.net.SocketException: Software caused connection
abort: socket write
error
        at
java.net.SocketOutputStream.socketWrite0(Native
Method)
        at
java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92)
        at
java.net.SocketOutputStream.write(SocketOutputStream.java:136)
        at
org.apache.commons.httpclient.HttpConnection.write(HttpConnection.java:693)
        at
org.apache.commons.httpclient.HttpConnection.write(HttpConnection.java:652)
        at
org.apache.commons.httpclient.HttpConnection.print(HttpConnection.java:772)
        at
org.apache.commons.httpclient.HttpMethodBase.writeRequestHeader(HttpMethodBa
se.java:2036)
        at
org.apache.commons.httpclient.HttpMethodBase.writeRequest(HttpMethodBase.jav
a:1972)
        at
org.apache.commons.httpclient.HttpMethodBase.processRequest(HttpMethodBase.j
ava:2298)
        at
org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.java:915
)
        at
com.eeft.mopserver.test.provider.orange.ApacheClientTest.run(ApacheClientTes
t.java:70)
        at
com.eeft.mopserver.test.provider.orange.ApacheClientTest.main(ApacheClientTe
st.java:82)

Thanks in advance,

Eric Johnson (not the one contributing to this
project)


__________________________________________________
Do you Yahoo!?
Yahoo! Shopping - Send Flowers for Valentine's Day
http://shopping.yahoo.com