chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Reading bytes from a TCP port


From: Fredrik Appelberg
Subject: Reading bytes from a TCP port
Date: Wed, 27 Nov 2019 12:13:55 +0100

Hello all, new chicken schemer here.

I'm writing an AMPQ client for fun (as One does) and can't figure out
the correct way to read from a TCP port. I want to block until input is
available, and then read all buffered data into a byte buffer (I'm using
bitstring, but it can be anything really). This is what I've come up with:

(let* ((buf (->bitstring ""))
       (first-byte (read-string 1 in)))
  (if (eq? #!eof first-byte)
      ... handle eof
      (begin 
        (bitstring-append! buf (string->bitstring (string-append first-byte 
(read-buffered in))))
        ... do something with buf))

It works okay, but it seems a bit clunky to me. Is there a more
idiomatic way of reading a byte buffer from a port?

Cheers,
-- Fredrik



reply via email to

[Prev in Thread] Current Thread [Next in Thread]