in reply to Re^2: Waiting for input, without sleep
in thread Waiting for input, without sleep

That doesn't answer anything. Strings are objects consisting of a length and a series of characters. How do you encode these (individually if applicable, and as a whole)?

Replies are listed 'Best First'.
Re^4: Waiting for input, without sleep
by Trihedralguy (Pilgrim) on Jun 30, 2009 at 16:10 UTC
    I'm not sure what to say really. I open a socket and get a message back from the server. My initial script above works just fine however, I was just thinking there might be a better way to get the message back.

    The server is sending the message back to me in HEX, but as you can guess by my function name, i'm displaying the hex version and converting it to a "string" or human readable stuff.

      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.