Java blocking socket returning incomplete ByteBuffer
Posted
by evandro-carrenho
on Stack Overflow
See other posts from Stack Overflow
or by evandro-carrenho
Published on 2010-04-26T21:27:39Z
Indexed on
2010/04/26
21:33 UTC
Read the original article
Hit count: 197
I have a socketChannel configured as blocking, but when reading byte buffers of 5K from this socket, I get an incomplete buffer sometimes.
ByteBuffer messageBody = ByteBuffer.allocate(5*1024);
messageBody.mark();
messageBody.order(ByteOrder.BIG_ENDIAN);
int msgByteCount = channel.read(messageBody);
Ocasionally, messageBody is not completely filled and channel.read() does not return -1 or an exception, but the actual number of bytes read (which is less than 5k).
Has anyone experienced a similar problem?
© Stack Overflow or respective owner