syndicate-2017/racket/syndicate/examples/actor/echo.rkt

14 lines
607 B
Racket

#lang syndicate
(require syndicate/protocol/advertise)
(require/activate syndicate/drivers/tcp)
(define server-id (tcp-listener 5999))
(spawn (assert (advertise (observe (tcp-channel _ server-id _))))
(during/spawn (advertise (tcp-channel $c server-id _))
(on-start (printf "Accepted connection from ~v\n" c))
(assert (advertise (tcp-channel server-id c _)))
(on (message (tcp-channel c server-id $bs))
(send! (tcp-channel server-id c bs)))
(on-stop (printf "Closed connection ~v\n" c))))