Hi guys, I'm really sorry for this post, but I still couldn't solve my problem.
well as API says, BufferedReader readLine() method returns null if end of the stream (EOS) reached. but it waits, here is my code.
the above code listens on port x and reads the Incoming stream from the client(Browser e.g. FF, IE) and parse it (very simple http server).
generally I'm not wondered using BufferedReader, any solution that help me out to solve this problem, I've tried to use InputStreamReader and InputStream classes but I could not.
my config: winxp sp2(sorry),tested in both JDK220.127.116.11 and Apache harmony 6M2 (same result).
Here you are reading from Socket, and Socket input stream could be considered as "endless" stream. So readLine will never read null, so to reach line 14 of your code you should use some sort of flag indicating end of the stream.
Joined: Jan 13, 2009
Hi Andrey Kozhanov.
well because it's a http server I don't have any hand to handle requests from clients, generally clients are browsers, so as you mentioned, how can I determine that browser(client) stream is completed and getting into the line 14? any solution? is there any standard belong browsers to notify servers about complete incoming stream?
Arash M. Dehghani wrote: is there any standard belong browsers to notify servers about complete incoming stream?
Yes, there is. It is the Hypertext Transfer Protocol (HTTP). If you are writing a server, you will want to become very familiar with it.
To answer your question directly, I believe an HTTP request ends with two carriage returns, but I wouldn't bet my life on it.
HI Joe, thanks for helping, well I read the HTTP rfc and it says
The Request-Line begins with a method token, followed by the Request-URI and the protocol version, and ending with CRLF. The elements are separated by SP characters. No CR or LF is allowed except in the final CRLF sequence.
well the CRLF is known as "\r\n" and when I tried to determine the end of the stream with this (Just in GET method)
it has the same result, waiting....
but I tried it like this
it seems work fine (but I cannot bet on it) with get method, when for methods which has body it requires some condition of course.
so the new question is, according to http rfc and spec, how to determine it? I mean CRLF.
Read 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.
A String containing the contents of the line, not including any line-termination characters, or null if the end of the stream has been reached
Joined: Jan 13, 2009
I think I have to swap my eyes
many thanks Joe, I've just got a big help, as you said and according to API the following code may help. does it? I think.