No reason to flush DataOutputStream.write?
I have a client that sends some bytes to a server with DataOutputStream. The server receives them with DataInputStream,readFully().
For some reason this works fine eventhough I don't flush each time after calling write on the client side.
When I use PrinWriter on the same socket I have to flush after each println call.
Why the difference?
[367 byte] By [
lokpesta] at [2007-10-3 5:21:15]

> I have a client that sends some bytes to a server
> with DataOutputStream. The server receives them with
> DataInputStream,readFully().
>
> For some reason this works fine eventhough I don't
> flush each time after calling write on the client
> side.
>
> When I use PrinWriter on the same socket I have to
> flush after each println call.
>
> Why the difference?
I would guess the latter (PrintWriter) keeps an internal buffer which needs to be flushed to the actual stream, whereas the former has no buffer, so even if you were to invoke flush() on it, it would have no effect.