问题
I read this question and other questions related to this but did not get any direct answer.
I need to send data to the client immediately for performance issue. I don't need Nagle's algorithm to efficiently send data.
Socket sock = new Socket("localhost", 1234);
sock.setTcpNoDelay();
OutputStream output = sock.getOutputStream();
for(int i = 0; i < 100; i++){
output.write(dataByteArray);
output.flush();
Thread.sleep(delayTime);
}
My question is: as I have set sock.setTcpNoDelay()
do I really need to use output.flush()
to request OS to send network buffer data immediately?
来源:https://stackoverflow.com/questions/49300186/java-forcing-a-tcp-socket-to-send-data-immediately