Hi,
I can't explain to myself an annoying bug I've got in my http server &
client code.
The server itself is the dumbest http server you can make. A class that
listens to a port and spawns threads to handle the incoming connections.
The client is of course using httpclient and there too, nothing too
complicated.
But,
I've got a bug I can't find a way to sweep out of the code. The tricky
thing is, it occurs randomly. I'm using the same code, I'm sending the
same message but somtimes it works, sometimes it hangs.
It hangs when receiving the message. Here's the code that reads the
request:
ByteArrayOutputStream body = new ByteArrayOutputStream();
byte[] buffer = new byte[2048];
int count = 0;
int totalCount = 0;
while ( (totalCount < contentLength) && ((count =
inputStream.read(buffer)) > 0) && (! this.kill) ) {
Logger.getLogger(this.getClass()).debug("run() : read "+count+"
bytes. total="+totalCount);
totalCount += count;
body.write(buffer, 0, count);
Logger.getLogger(this.getClass()).debug("run() : written "+count+"
bytes. total="+totalCount);
}
And the trace I've got when things work fine :
run() : read 2048 bytes. total=0
run() : written 2048 bytes. total=2048
run() : read 2048 bytes. total=2048
run() : written 2048 bytes. total=4096
run() : read 2048 bytes. total=4096
run() : written 2048 bytes. total=6144
run() : read 2048 bytes. total=6144
run() : written 2048 bytes. total=8192
run() : read 778 bytes. total=8192
run() : written 778 bytes. total=8970
However, sometimes I run the server and the client and here's what happens:
run() : read 1326 bytes. total=0
run() : written 1326 bytes. total=1326
/**** the program hangs here until timeout then it throws: ****/
java.net.SocketTimeoutException: Read timed out
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(SocketInputStream.java:129)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:183)
at java.io.BufferedInputStream.read(BufferedInputStream.java:201)
at
org.apache.commons.httpclient.HttpParser.readRawLine(HttpParser.java:77)
at
org.apache.commons.httpclient.HttpParser.readLine(HttpParser.java:105)
at
org.apache.commons.httpclient.HttpConnection.readLine(HttpConnection.java:1115)
at
org.apache.commons.httpclient.MultiThreadedHttpConnectionManager$HttpConnectionAdapter.readLine(MultiThreadedHttpConnectionManager.java:1373)
at
org.apache.commons.httpclient.HttpMethodBase.readStatusLine(HttpMethodBase.java:1832)
at
org.apache.commons.httpclient.HttpMethodBase.readResponse(HttpMethodBase.java:1590)
at
org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.java:995)
at
org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:397)
at
org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:170)
at
org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:396)
at
org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:324)
I really don't know have a clue so if anyone had an advice or some
previous experience of this issue, I'd be glad to hear from you.
Thanks,
Julien
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]