On Tue, 02 Oct 2007 12:00:21 -0000, roele <roland.sch...@gmail.com>
wrote:
I have a method where i will handle an Input/Output Stream from a
ServerSocket. The Client sends several requests and these should be
handled in one connection.
The first request is handled as expected but the seconds request is
blocked by the requestReader.readLine() method... According to JavaDoc
i cant find anything about readLine() blocking.
Has anybody a clue what could be wrong here?
--
public void handleRequest() throws IOException {
BufferedReader requestReader = new BufferedReader(new
InputStreamReader(socket.getInputStream));
OutputStream responseStream = new
BufferedOutputStream(socket.getOutputStream());
do {
Request request = new Request();
Response response = new Response();
parseRequest(requestReader, request);
processRequest(request, response);
writeResponse(responseStream, response);
}while(keepAlive && !hasError);
request.close();
response.close();
socket.close();
}
private void parseRequest(HttpRequest request) throws IOException {
String reqString = requestReader.readLine();
//.. do something with String here
//Read on
while(requestReader.ready()) {
String reqHeaders = requestReader.readLine();
//Reached end?
if(reqHeaders == null || reqHeaders.length() == 0) {
break;
}
//.. do something with String here
}
}
The documentation says: "Reads a line of text. A line is considered to
be terminated by any one of a line feed ('\n'), a carriage return
('\r'), or a carriage return followed immediately by a linefeed."
I have had problems in similar circumstances when the incoming stream
was not terminated with and end-of-line character. This might be what
is happening here if readLine is waiting for the current line to
complete before returning and in the absence of an end-of-line it just
keeps waiting and does not return.
rossum