Can i write to data output stream after reading response from data input stream?
i want to do a client-server activity like this: 1. first the client sends/writes to output stream 2. the server responses with some data that will be read with开发者_运维知识库 input stream 3. after receiving the data, the client sends/writes to output stream again to respond that the data has been received
now, do i have to close the output stream and re-open it again before doing step no.3 ? also if someone could provide me with a snippet, it would be really helpful. thanks
You could if you want to, but you don't need to. However, you would need to flush()
after writing to the OutputStream
in case it is buffered.
The problem would be to know when to read. If the number of bytes to be read is available and performance is not an issue, you can use the blocking call readFully
. But this is just one possible strategy.
精彩评论