read-line returns eof when the port is closed, which is completely different from sending byte 04 (or any other byte or sequence of bytes) over the port.

  ;; set up {client,server}-{in,out} ports
  (write-byte 4 client-out)
  (flush-output client-out)
  (read-byte server-in) ;; => 4
  (close-output-port client-out)
  (read-byte server-in) ;; => #<eof>

If you want to consider U+0004 a line-breaking character, you'll have to write the code that does that yourself. Using regexp-match on the input port might be the most convenient way.

Ryan


On 02/22/2017 07:49 PM, Jordan Johnson wrote:
Hi all,

Quick question: Given a listener and input port defined thus:

        (define listener (tcp-listen port))
        (define-values (in out) (tcp-accept listener))

while reading lines of text, what’s the correct way to detect an EOT (^D or 
U+0004) character?

This “obvious” solution does not work:

        (for ([line (in-lines in)])
             #:break (eof-object? line)
          ...)

Neither does this (which I wouldn’t expect to work, after the above didn’t):
        (let loop ([val (read-line in)])
          (unless (eof-object? val)
            ...))

I’ve determined that the eof-object? calls are never producing #t, even if ^D 
is the very first thing the client sends. I’m thinking there’s something 
super-basic that I’m forgetting.

What am I missing here?

Thanks,
Jordan


--
You received this message because you are subscribed to the Google Groups "Racket 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to