Echo server example

This commit is contained in:
Tony Garnock-Jones 2015-08-18 12:45:29 -04:00
parent 2e3a8fceaa
commit 02c5ee97d3
1 changed files with 24 additions and 0 deletions

View File

@ -0,0 +1,24 @@
#lang prospect
(require "../drivers/tcp.rkt")
(require "../demand-matcher.rkt")
(define server-id (tcp-listener 5999))
(spawn-tcp-driver)
(spawn-demand-matcher (advertise (tcp-channel (?!) server-id ?))
(observe (tcp-channel (?!) server-id ?))
(lambda (c)
(printf "Accepted connection from ~v\n" c)
(spawn (lambda (e state)
(match e
[(? patch/removed?)
(printf "Closed connection ~v\n" c)
(quit)]
[(message (tcp-channel src dst bs))
(transition state (message (tcp-channel dst src bs)))]
[_ #f]))
(void)
(sub (advertise (tcp-channel c server-id ?)))
(sub (tcp-channel c server-id ?))
(pub (tcp-channel server-id c ?)))))