Sockets: BufferedOutputStream or just OutputStream?

杀马特。学长 韩版系。学妹 提交于 2019-11-29 06:33:27

I don't know where you read all that nonsense but it is completely back to front. The more you write at a time to a TCP connection the better, and the more you read from it at a time ditto. I would always use a buffered stream, reader, or writer between the application and the socket streams. There are some cases like SSL where directly writing a byte at a time can cause a 40x data explosion.

Is it a good idea to touch the TCP window size? For example by setting it to 64 KiB

You can't 'touch the TCP window size'. You can increase its maximum value via the APIs you mention, and that is indeed a good idea.

What do you mean by speed? low latency or high throughput?

For low latency, flush the stream as soon as you finish writing to it.

For high throughput, use a buffered stream and let the VM/OS handle its flushing.

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