Reputation:
After asking this question Writing to TcpClient and NetworkStream it appears i must write yet another stream which will read in a smaller stream and keep going until i get the size i like (or until error/timeout).
Is there anything built in? Or in a popular 3rd party library? I just want to make sure my TCP readlength is big enough to initialize my structs or fill an array before i start doing operations on it. So i'd like Read() to block until it is ready. Perhaps throw an exception when the underlying stream (TCP) timeout or is closed on the other size. (or is EOF which would be useful with file IO streams).
Upvotes: 1
Views: 74
Reputation: 244868
I think BinaryReader.ReadBytes()
is exactly what you want. It can return less than the requested number of bytes, but, according to the documentation, that only happens when the end of the stream is reached.
Upvotes: 1