(define* (export-server #:optional (host "127.0.0.1") (port 2904))
  "Listen on HOST and PORT for connections from clients that request a
store item.  Respond by piping a stream of the requested store item
and its dependencies to the client."
  (let ((s (socket PF_INET SOCK_STREAM 0)))
    (setsockopt s SOL_SOCKET SO_REUSEPORT 1)
    (bind s AF_INET (inet-pton AF_INET host) port)
    (listen s 5)

    (simple-format #true "Listening on ~a:~a~%" host port)
    (newline)

    (while #true
      (match (accept s)
        ((client . _)
         (setvbuf client 'none)
         (let ((thing (read client)))
           (format (current-output-port) "sending `~a'~%" thing)
           (parameterize ((current-output-port client))
             ;; produce output here...
             (display "lots of data")
             ))
         (force-output client)
         (close client))))))

Generated by Ricardo Wurmus using scpaste at Wed Mar 24 08:58:31 2021. CET. (original)