Java forcing a TCP socket to send data immediately

♀尐吖头ヾ 提交于 2019-12-10 12:14:32

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!