K
Kiran Kumar
Hello,
API doc for reading (read method ) from SocketChannel says:
______________________________________________________________________________
A read operation might not fill the buffer, and in fact it might not read any
bytes at all. Whether or not it does so depends upon the nature and state of the
channel. A socket channel in non-blocking mode, for example, cannot read any more
bytes than are immediately available from the socket's input buffer; similarly, a
file channel cannot read any more bytes than remain in the file. It is guaranteed,
however, that if a channel is in blocking mode and there is at least one byte
remaining in the buffer then this method will block until at least one byte is
read.
______________________________________________________________________________
ByteBuffer buffer = ByteBuffer.allocate(2048);
if( key.isReadable() ){
SocketChannel channel = (SocketChannel) key.channel();
channel.read(buffer);
key.cancel();
}
Say client sends 20 bytes of data. I hope the doc does't mean that I *might*
get 3 bytes now and 17 bytes *later*. Probably there is somethign wrong
with my understanding. Can anyone please clarify. Surely, nothing can be
with nio if there is such uncertainity.
Kiran
API doc for reading (read method ) from SocketChannel says:
______________________________________________________________________________
A read operation might not fill the buffer, and in fact it might not read any
bytes at all. Whether or not it does so depends upon the nature and state of the
channel. A socket channel in non-blocking mode, for example, cannot read any more
bytes than are immediately available from the socket's input buffer; similarly, a
file channel cannot read any more bytes than remain in the file. It is guaranteed,
however, that if a channel is in blocking mode and there is at least one byte
remaining in the buffer then this method will block until at least one byte is
read.
______________________________________________________________________________
ByteBuffer buffer = ByteBuffer.allocate(2048);
if( key.isReadable() ){
SocketChannel channel = (SocketChannel) key.channel();
channel.read(buffer);
key.cancel();
}
Say client sends 20 bytes of data. I hope the doc does't mean that I *might*
get 3 bytes now and 17 bytes *later*. Probably there is somethign wrong
with my understanding. Can anyone please clarify. Surely, nothing can be
with nio if there is such uncertainity.
Kiran