Skip to Main Content

Java APIs

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Socket DataInputStream read SocketTimeException

843790Oct 9 2008 — edited Oct 10 2008
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.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 7 2008
Added on Oct 9 2008
5 comments
286 views