开发者

Flush operation for Java non-blocking socket

In normal blocking socket, I can use Socket.getOutputStream().flush() to partly control when to send out a TCP packet. Is there an equivalent operation for SocketChannel?

Edit: My guess is that every time I call SocketChannel.write(ByteBuffer src), at least one individual packet will be sent, even the buffer has only 1 byte(assume Nagle 开发者_StackOverflow社区is off), am I right?

Edit: package -> packet, sorry for wrong spelling.


I guess you could write something like

while (buf.hasRemaining()) {
    socketChan.write(buf);
}

Perhaps there is a better solution.


As I noted recently Socket.getOutputStream().flush() does nothing in Sun's JDK 6.

However, there is no guarentee that write() will send one packet (not package) it could send more or less. All you know is it has been passed to the OS to handle it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜