• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

BufferedReader .readLine() is not seeing end of file

 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic