On 09/03/2014 12:01 PM, Gilbert Martinez wrote:
I'm having issues reading the response from a TCP server. Specifically, any attempt to read the input port does not terminate. I've used port->bytes, read-byte, and read-line. In all cases the effect is the same.

I thought that if there were no bytes available on an input port that the read attempt would just return <eof>. Is this some kind of exclusivity issue? Can I not read from the port until the connection with the server is closed or something?
This is not true. Most functions like 'read-byte' block until there are bytes available to read. You don't get <eof> until the port (connection) is closed. If you want a non-blocking call, look at 'read-bytes-avail!*'.

#lang racket

(define-values (in out) (make-pipe))

(thread
 (lambda ()
   (for ((i 5))
     (write-byte i out)
     (sleep 1))
   (close-output-port out)))

(for ((b in))
  (printf "~x " b))

'for' is pretty smart in my experience. I believe in this case it's using a sequence from 'in-port'. But in any case, you should see numbers print out before the port is closed.

Does this help?

Thanks,
Dave
____________________
  Racket Users list:
  http://lists.racket-lang.org/users

Reply via email to