From 02c5ee97d3630601043035901c256a35b546daf0 Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Tue, 18 Aug 2015 12:45:29 -0400 Subject: [PATCH] Echo server example --- prospect/examples/echo.rkt | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 prospect/examples/echo.rkt diff --git a/prospect/examples/echo.rkt b/prospect/examples/echo.rkt new file mode 100644 index 0000000..ea7a55e --- /dev/null +++ b/prospect/examples/echo.rkt @@ -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 ?)))))