0

Possible Duplicate:
java socket / output stream writes : do they block?

When writing to a DataOutputStream attached to a Socket, for example in a Server-to-Client connection, does the .writeInt() method wait for the data to be written, if, for example, the Client/Server connection is very slow - would this make the .writeInt() method wait?

Community
  • 1
  • 1
  • how are you initializing the `DataOutputStream` ? is it wrapped in a `BufferedOutputStream` ? – Bala R Jan 14 '13 at 21:37

1 Answers1

0

It will wait until

  • there is enough space in the send buffer to copy the data.
  • the data is sent to the OSes buffer.

For this reason it is a good idea to Buffer the stream (to reduce the cost of system calls).

No matter what you do you have the potential to be blocked as the connection is too slow.

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130