in reply to Waiting for input, without sleep

There are a couple of odd things about your code:

If you use sysread without an offset parameter, then it will always read into the start of your buffer. That means that if your server's response happened to turn up in more than one packet, you might trash the first bit of content with the second. I guess you might not see this if the responses are small enough to fit in one packet, but that's more by luck than judgement, especially if the data could be up to 4000 bytes in length.

Your algorithm for reading the response is a bit odd:

  1. Wait 4s for server to do its thing
  2. Enter a loop, reading anything that turns up (but always overwriting the start of the buffer, as noted)
  3. Abort the loop after 1s, no matter what (if anything) arrived
  4. Close socket
  5. Hope that whatever arrived is OK
You might want to consider either:

--
use JAPH;
print JAPH::asString();