A method that polls a stream for arrival of a complete string with the ReadAvail (to avoid blocking) would be even more complicated than your example code above.
Currently the presence of 4 bytes available on the incoming stream guarantees you can read the string length without blocking.
Currently the presence of 4 bytes available on the incoming stream guarantees you can read the string length without blocking.
That's true. You'd have to wait for one byte available, read it, and then decide if you have to wait any longer for the next 1-4 bytes. It's an extra step from what you have to do now, but not a very CPU intensive one. Not too hard to code though if you know the string format?