Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

endless loop condition  RSS feed

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

Working on a client/server chat application. On the client side app, everytime I want to send a message I create a new Thread called "SendingThread". See below.

As you can see the line writer.close() is important in regard to a Thread that is running on the server app called "ReceivingThread" (see below). In the ReceivingThread there is a line:
if((temp = input.readLine()) != null)

It blocks until I actually send a message to read in. This is expected. However, now I have a catch 22 situation. On the client side app, since I called writer.close(), this was necessary in order to get a null value during the readLine() call on the ReceivingThread on the server. The one line gets processed as expected. The stream is now closed and on the server side app, since this is true, the next iteration of the while loop attempts to read in another line but now it is alway null and thus I wind up with an endless loop condition. I introduced a "count" variable and a condition only so that the loop wouldn't get away too far. I was hoping it would block again, but it isn't. I believe the ReceivingThread is written correctly, but I need to somehow obtain a null value on the stream for message completion and also have the ReceivingThread block for the next message coming in.

Please advise,


[ November 21, 2007: Message edited by: Alan Shiers ]
[ November 21, 2007: Message edited by: Alan Shiers ]
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!