syndicate-rkt/syndicate-examples/echo.rkt

14 lines
525 B
Racket

#lang syndicate
(require/activate syndicate/drivers/tcp)
(spawn (during/spawn (tcp-connection $id (tcp-listener 5999))
(on-start (printf "Accepted connection ~v\n" id))
(on-stop (printf "Closed connection ~v\n" id))
(assert (tcp-accepted id))
(on-start (issue-credit! (tcp-listener 5999))
(issue-credit! tcp-in id))
(on (message (tcp-in-line id $bs))
(issue-credit! tcp-in id)
(send! (tcp-out id (bytes-append bs (bytes 13 10)))))))