• Post Reply Bookmark Topic Watch Topic
  • New Topic

BufferedReader's readLine() is giving null when listening for the socket connection for second time.

 
M Mohile
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ranchers,
This is a simple one-way interaction (from server to client) client-server program that makes changes on the client-side on the basis of whatever is being sent from the socket over server-side. There is absolutely no issue on the server but on the client-side, BufferedReader's readLine() method is giving "null" even when nothing is being sent over the socket from server-side. I've read the article Don't println() to a socket in I/O FAQs and tried implementing the solution provided but unfortunately the issue remains unsolved. Here, I've also marked where exactly the problem is coming (on the client-side) as you move along the code which is as follows:

Server-side code:


Client-side code:


This class is on client-side.



If you wish to run this, create a file "MappingFile.txt" & fill it line-by-line such that x1:1 and so on till x8:8
And yes, I'm using Windows OS.

Thanks..

 
Tony Docherty
Saloon Keeper
Posts: 3142
72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please UseCodeTags (← click) when posting code as it makes it easier for people to read your code. I've added them for you this time.
 
M Mohile
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Tony...will be surely careful in future..
 
Tony Docherty
Saloon Keeper
Posts: 3142
72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your send actionListener closes the stream after sending the text (in the finally clause) and readLine() returns null when the end of the stream has been reached, which it has when the stream has been closed.
 
M Mohile
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Tony... the issue has been resolved!!
 
Tony Docherty
Saloon Keeper
Posts: 3142
72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My pleasure
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!