My initial script above works just fine
More like "My initial script happened to work when I ran it". I wouldn't call that "fine". It's incredibly fragile since you have no way of knowing if you're received all incoming data or not.
One usually reads a constant number of bytes, a previously transmitted number of bytes or until a sentinel is encountered. Reading for a predetermined amount of time is a new one for me.
Even if the whole string has arrived within the four seconds, a single sysread is not guaranteed to get all by bytes.
|