Hi all,
I got a socket client/server, but while read(), the client do heartbeat every 1/4 second, and following is the heartbeat's mainly code.
The question is there will be a Timeout exception intermittently. I mean it during 100 times heartbeats, there will 1~2 times failed to read(), but the followed thrid can successfully read from the inputStream.
socketClient.setSoTimeout(10*1000); // timeout 10s
DataInputStream input = socketClient.getInputStream();
byte[] outputData = null;
try {
byte[] outputDataTemp = new byte[252];
COSLogger.doInfo("ModbusRequest", "execute", "input.available() = "+input.available()); // why available() always is 0?
int size = input.read(outputDataTemp);// SocketTimeoutException occured here
if (size <= 0) {
throw new Jnior310Exception("Invalid zero-length response from jnior.");
}
outputData = new byte[size];
for (int i = 0; (i < size); i++) {
outputData[i] = outputDataTemp;
}
} catch (IOException e) {
throw new Jnior310Exception("IOException on read: " + e);
}Any reply is appreciated.