#lang syndicate ;; -*- racket -*-

(require "../drivers/tcp.rkt")
(require "../demand-matcher.rkt")

(define server-id (tcp-listener 5999))

(spawn-tcp-driver)
(actor (forever
        (on (asserted (advertise (tcp-channel $c server-id ?)))
            (printf "Accepted connection from ~v\n" c)
            (actor (until (retracted (advertise (tcp-channel c server-id ?)))
                     (advertise (tcp-channel server-id c ?))
                     (on (tcp-channel c server-id bs)
                         (send! (tcp-channel server-id c bs))))
                   (printf "Closed connection ~v\n" c)))))
