Question:
How can I use buffered I/O Object streams over a socket and guaranteetransmission even when the packet object is smaller than the buffersize? I want the efficiency benefits of buffered streams whensending large packets, but I need to force small packets throughimmediately.
Answer:
You must use the flush() method to force all data buffered in a BufferedOutputStream to be written to the underlying output stream. If you have wrapped a socket with a BufferedOutputStream, this will force all the buffered data to be sent over the socket.