I have written an application that transfers data across a network using Socket, getInputStream(), getOutputStream(). I have some concerns about how to optimize for performance.
Currently I am writing one byte at a time to the OutputStream. I am wondering if this results in a separate TCP packet being sent for each byte, which would obviously be very inefficient. Or does it buffer the data into a packet before sending?
If I need to wrap my OutputStream, what is the recommended way to do it?
Geoffrey Falk wrote:. I am wondering if this results in a separate TCP packet being sent for each byte,
No. The OS is going to do some caching of its own. Of course, it is always better to make fewer API calls if possible. The online book Java Platform Performance has several techniques to optimize IO.