wood burning stoves 2.0*
The moose likes Java in General and the fly likes BufferedReader .readLine() is not seeing end of file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "BufferedReader .readLine() is not seeing end of file" Watch "BufferedReader .readLine() is not seeing end of file" New topic
Author

BufferedReader .readLine() is not seeing end of file

Lon Allen
Ranch Hand

Joined: May 24, 2001
Posts: 67
I am wanting to pass an xml formatted string from a client to a server. The server will manipulate the data and send it back to the client. For now I am just reading the file in using a BufferedReader, sending the contents to the server and echoing it back. The problem I am having is that when passing the contents of the file to the server there is no EOF marker since the while loop I use is triggered by .readLine() != null.
The following code is in the client and sends the file contents to the server.

In this block of code there are two "while" loops that are controlled by ".readLine() != null". The first one works fine (since it is reading the data from am actual file), but the second one never quits the loop on the returned data.
I am assuming that since the first loop exits before an EOF character can be written to the socket that the returned data doesn't have an EOF character to key off of.
My server has a similar loop that sends the received lines back to the client. It too has the same problem with the while loop.


How can I insert an EOF character into the stream so that the while loops that are reading lines on an input stream have a means of exiting the loops?
TIA
Lon Allen
Lon Allen
Ranch Hand

Joined: May 24, 2001
Posts: 67
I figured it out. I put the following at the end of sending the data in the client:
socketWriter.println("\u0004"); //after while loop
and changed the while loop in the server to
while (!(lineIn = socketReader.readLine()).equals("\u0004"))
works good now.
[ June 16, 2003: Message edited by: Lon Allen ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: BufferedReader .readLine() is not seeing end of file
 
Similar Threads
Buffer size or other? Please help
communicate question for socket server and client
Problem with echo server and client.
how to add XML Data into Jtext area
sending images over server socket to browser page