I create a session for data exchange. And use simple method for read
static int read(InputStream in, byte[] buf, int start, int len)throws IOException, TimeoutException {
int read = 0;
int pos = start;
int total = 0;
while (total < len && (read = in.read(buf, pos, len - total)) != -1) {
pos += read;
total += read;
}
if (pos != len) {
throw new ProtocolException(String.format(
"Read data failed %d!=%d(expected), RAW=%s", total, len,
Crc16.hexString(buf, start, len)));
}
return pos;
}
Time from time it working ok.
But time from time, method read still blocking and not return data. Looking like as no flush on sender. But if the stop reading, I see all data is received and kept in the buffer. And all data sent 100% of cousrse to this session.
For example (this is print of tails of send and received)
SENT
..... A1 BD 24 16 14 AE 00 00 4B E0 , total=1078
RECEIVED
..... A1 BD 24 16 14 AE 00 00 4B E0 (4BE0 CRC16)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I create a session for data exchange. And use simple method for read
static int read(InputStream in, byte[] buf, int start, int len)throws IOException, TimeoutException {
int read = 0;
int pos = start;
int total = 0;
while (total < len && (read = in.read(buf, pos, len - total)) != -1) {
pos += read;
total += read;
}
if (pos != len) {
throw new ProtocolException(String.format(
"Read data failed %d!=%d(expected), RAW=%s", total, len,
Crc16.hexString(buf, start, len)));
}
return pos;
}
Time from time it working ok.
But time from time, method read still blocking and not return data. Looking like as no flush on sender. But if the stop reading, I see all data is received and kept in the buffer. And all data sent 100% of cousrse to this session.
For example (this is print of tails of send and received)
SENT
..... A1 BD 24 16 14 AE 00 00 4B E0 , total=1078
RECEIVED
..... A1 BD 24 16 14 AE 00 00 4B E0 (4BE0 CRC16)