Echo example in actor form

This commit is contained in:
Tony Garnock-Jones 2016-01-13 11:26:01 -05:00
parent 99466dad7f
commit 4faf189029
1 changed files with 18 additions and 0 deletions

View File

@ -0,0 +1,18 @@
#lang prospect
(require prospect/actor)
(require prospect/drivers/tcp)
(actor-body->spawn-action
(lambda ()
(perform-core-action! (spawn-tcp-driver))
(define server-id (tcp-listener 5999))
(forever (assert (advertise (observe (tcp-channel _ server-id _))))
(on (asserted (advertise (tcp-channel $c server-id _)))
(printf "Accepted connection from ~v\n" c)
(actor (until (retracted (advertise (tcp-channel c server-id _)))
(assert (advertise (tcp-channel server-id c _)))
(on (message (tcp-channel c server-id $bs))
(send! (tcp-channel server-id c bs))))
(printf "Closed connection ~v\n" c))))))