DaFou
asked on
readling all of the BufferedReader
Ola,
I want to fill up a string withh all there is in the BufferedReader, But i can only read line by line.
And when I loop through it my code hangs:
please debug this code:
InputStream lInputStream = lSocket.getInputStream();
BufferedReader lBufferedReader = new BufferedReader( new InputStreamReader( lInputStream ) );
String lStrRequest = "";
String lStr = lBufferedReader.readLine() ;
while ( lStr != null ) // why is this loop never ending and makes my code hang?
{
lStrRequest += lStr;
lStr = lBufferedReader.readLine() ;
}
System.out.println( lStrRequest );
I want to fill up a string withh all there is in the BufferedReader, But i can only read line by line.
And when I loop through it my code hangs:
please debug this code:
InputStream lInputStream = lSocket.getInputStream();
BufferedReader lBufferedReader = new BufferedReader( new InputStreamReader( lInputStream ) );
String lStrRequest = "";
String lStr = lBufferedReader.readLine()
while ( lStr != null ) // why is this loop never ending and makes my code hang?
{
lStrRequest += lStr;
lStr = lBufferedReader.readLine()
}
System.out.println( lStrRequest );
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Interesting advice.
a. i cant arange the protocol since I am using a standard http webbrowser to connect.
this is the first line of the browser request:
"GET / HTTP/1.1Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-fl ash, application/vnd.ms-excel, application/vnd.ms-powerpo int, application/msword, */*Accept-Language: en-gb"
b. No no closing :-) i am making a chatserver remember?
c. hmm non blocking IO? I am not sure that is usefull and the socket is only used to send info and not read. I only need to read the initial request to determine wether to store the request as a client object or to parse incomming chatmessages from.
I think ill simply read the first 3 or 4 lines using a for ( ) loop
a. i cant arange the protocol since I am using a standard http webbrowser to connect.
this is the first line of the browser request:
"GET / HTTP/1.1Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-fl
b. No no closing :-) i am making a chatserver remember?
c. hmm non blocking IO? I am not sure that is usefull and the socket is only used to send info and not read. I only need to read the initial request to determine wether to store the request as a client object or to parse incomming chatmessages from.
I think ill simply read the first 3 or 4 lines using a for ( ) loop
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
and how would i read all of the http request ( including form fields and data ) but break out of the loop once the
lBufferedReader.readLine() does not find anything anymore ( after all of the request was read )?.
lBufferedReader.readLine()
ASKER
sorry i think i understand now :-)
ASKER
ill make a new question :-)
ASKER
CEHJ, your code works like a charm, its getting later and i am beginning to make mistakes :)
a. arrange the protocol so the sending entity sends an end of transmission marker
b. make the sender close the socket
c. use non-blocking IO