I was wondering whether the output stream will be flushed when the JVM exits before the stream is closed i.e whether the FIN bit is set and the InputStream at the other end can process the data even though the data sent may or may not be malformed? My exact need is that I want to know whether the request has been sent successfully.
1 Answers
I was wondering whether the output stream will be flushed when the JVM exits
No.
before the stream is closed
The stream isn't closed. Any data that hasn't been flushed will be lost.
i.e whether the FIN bit is set
That's a completely different issue. The operating system will close the socket, send any remaining data that has been flushed, and send a FIN.
and the InputStream at the other end can process the data even though the data sent may or may not be malformed?
That's up to your code. The InputStream will receive whatever data had been flushed, and then the EOS.
My exact need is that I want to know whether the request has been sent successfully.
That is another, completely different, matter again. If you need to know that the peer application has received the data, it needs to send you an acknowledgment in the application protocol.
The basic idea is to make sure your streams get closed by the application.

- 305,947
- 44
- 307
- 483