简体   繁体   中英

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM