Q
Qu0ll
I have a ByteBuffer named "buf" which is created by the
ByteBuffer.allocate() method and is set to size 1024 bytes for each packet
to be sent over the network. I also have a SocketChannel named "channel" to
which I want to write multiple ByteBuffer packets. This is working but
after about 30 or so packets no data are transferred and the following code
shows that 0 bytes are being written for each subsequent packet:
++packetCount;
int size = buf.remaining();
int n = channel.write(buf);
if (n < size) {
System.out.println("PARTIAL WRITE (" + n + " < " + size + ") for
packet " + packetCount);
}
Given that it works for a while, this smells of some kind of buffering
problem. I know that output streams buffer things and that you can use the
flush() method to flush the buffer but I can't see how to do something
similar here given that I am writing directly to the channel.
Your thoughts?
--
And loving it,
-Q
_________________________________________________
(e-mail address removed)
(Replace the "SixFour" with numbers to email me)
ByteBuffer.allocate() method and is set to size 1024 bytes for each packet
to be sent over the network. I also have a SocketChannel named "channel" to
which I want to write multiple ByteBuffer packets. This is working but
after about 30 or so packets no data are transferred and the following code
shows that 0 bytes are being written for each subsequent packet:
++packetCount;
int size = buf.remaining();
int n = channel.write(buf);
if (n < size) {
System.out.println("PARTIAL WRITE (" + n + " < " + size + ") for
packet " + packetCount);
}
Given that it works for a while, this smells of some kind of buffering
problem. I know that output streams buffer things and that you can use the
flush() method to flush the buffer but I can't see how to do something
similar here given that I am writing directly to the channel.
Your thoughts?
--
And loving it,
-Q
_________________________________________________
(e-mail address removed)
(Replace the "SixFour" with numbers to email me)