(use tcp srfi-18 posix srfi-1)

(define listener (tcp-listen 8080))

(let loop ()
  (receive (in out) (tcp-accept listener)
    (thread-start! 
     (lambda ()
       (let ((x (read-string 10 in)))
         ;; (thread-sleep! 2)
         (print (current-seconds))
         (display x out)
         (flush-output out)

         (let ((no (##sys#tcp-port->fileno in)))
           (close-input-port in)
           (close-output-port out)
           (fprintf (current-error-port) "~A ~A~%"
                    (thread-name (current-thread)) 
                    no))))))
  (loop))