I am trying to read data from 5 devices connected serially. My Java code is running fine if the device is healthy, if not then inputstream.read()
hangs the program and does not allow further execution.
I have tried using inputstream.available()
, BufferedInputStream
... but nothing works.
What I want to do is: if a device does not respond my code, it should end itself and let the control go to the main program where it will go to the next device. The socket remains open for one cycle of polling.
Socket es = new Socket("10.12.90.153",4001);
OutputStream osnew= es.getOutputStream();
InputStream isnew = new BufferedInputStream(es.getInputStream());
This is done in the task program, then I pass osnew
and isnew
to each device at a gap of one second for further action. The osnew
writes some data to which the device responds. Then I read from isnew
...This where the program hangs.