• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

BufferedReader .readLine() is not seeing end of file

 
Lon Allen
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic