I have the following code to read data from a socket.
byte[] data = new byte[dataLength];
if(dataLength > 2000000)FileManager.writeToLogFile(this.getClass(), "GetIncomingMessages", LogMessageType.DEBUG, "XXXXYYYY => 2 length: " + dataLength);
for(int i = 0 ; i < dataLength ; i++){
byte[] temp = new byte[1];
in.read(temp);
data[i] = temp[0];
}
if(dataLength > 2000000)FileManager.writeToLogFile(this.getClass(), "GetIncomingMessages", LogMessageType.DEBUG, "XXXXYYYY => 3 length: " + dataLength);
This code works fine until I get a pack with the size of around 3MB (3227056 bytes to be exact). When this packet is received, no exception occurs, neither does my program crash, but the code never progresses beyond that point. Basically the last log entry that you see above is not made.
What could be the reason for this ? How could I at least figure out WHAT the error is ? (Error is not caught in any of the try-catch blocks). There are however, other receives that take place beyond this point.
dataLengthfrom? Another question: is this so inefficient on purpose?Stream.availableto check for how much data is available without blocking. Secondly you may want to useint Stream.read(byte[] buffer)to read a whole chunk of data to a buffer instead of byte-by-byte. This is a comment because it is not an answer to your question. Just some tipps.length: 3227056 bytesRead => 104252so only 104252 bytes were read. Would you be able to shed any light on possible reasons for this ?