开发者

Can i write to data output stream after reading response from data input stream?

开发者 https://www.devze.com 2022-12-31 18:48 出处:网络
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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号