Paul Clapham wrote:Well, the code you posted won't do that anyway, it will just block when it has to wait for data to arrive from the network partner.
<Kevin> Am I wrong in thinking the "if(super.ready())" will prevent my code from attempting to read a character if there is none?
However if your requirement is for the connection to time out if no data is received within a certain period, it would be better to just set that timeout on the socket, rather than trying to hack the system at a completely different level. Then you just write ordinary text-reading code which is prepared for IOExceptions to be thrown when the timeouts occur.
<Kevin> This may work. However, wouldn't the Socket shut down if there is a timeout? If so this would not be a good solution since I have to send the device a command after I finish even if I did not get all the data I was expecting. Also the other Device sends Keep Alive packets to me so wouldn't this prevent the timeout at the Socket level?
Also, if you don't want your application to be hung up by code waiting for input, it's usual in networking applications to run that code in a separate thread.
<Kevin>
I am already running it in a separate thread, so I mislead you a bit. The whole application won't hang up, but that thread would if Data doesn't come across.