Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

BufferedReader.readLine doesn't return null

 
Alan Shiers
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,

I'm trying to put together a simple Chat client/server application. The issue I'm having is with the Server app. I have a class that extends Thread which contains this call:
temp = input.readLine()
in the run() method. Everytime I connect with the client side app, an instance of this class "ReceivingThread" is created and is supposed to read in any messages coming in using a BufferedReader. That's the input variable type. According to the API readLine() is supposed to return null when there's nothing more to read in. In my code I check for null but it never seems to leave the while loop.

Please advise,

Alan

 
Joe Ess
Bartender
Posts: 9279
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Alan Shiers:
According to the API readLine() is supposed to return null when there's nothing more to read in.


Close. It returns null when the stream reaches EOF. It blocks when there's nothing more to read. You probably need to close the stream on the other end.
 
Alan Shiers
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yep. That was it!
Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic