From cdb9e1cb076e691ad95ef34815bb94d2a78561f6 Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Fri, 6 Mar 2015 13:58:36 +0000 Subject: [PATCH] Chat client example. --- prospect/examples/chat-client.rkt | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 prospect/examples/chat-client.rkt diff --git a/prospect/examples/chat-client.rkt b/prospect/examples/chat-client.rkt new file mode 100644 index 0000000..bed31b0 --- /dev/null +++ b/prospect/examples/chat-client.rkt @@ -0,0 +1,26 @@ +#lang prospect + +(require (only-in racket/port read-bytes-line-evt)) +(require "../drivers/tcp.rkt") + +(define local-handle (tcp-handle 'chat)) +(define remote-handle (tcp-address "localhost" 5999)) + +(spawn-tcp-driver) +(spawn/stateless (lambda (e) + (match e + [(? patch/removed?) (quit)] + [(message (at-meta (external-event _ (list (? eof-object?))))) + (quit)] + [(message (at-meta (external-event _ (list line)))) + (message (tcp-channel local-handle remote-handle line))] + [(message (tcp-channel _ _ bs)) + (write-bytes bs) + (flush-output) + #f] + [_ #f])) + (sub (external-event (read-bytes-line-evt (current-input-port) 'any) ?) + #:meta-level 1) + (sub (tcp-channel remote-handle local-handle ?)) + (sub (advertise (tcp-channel remote-handle local-handle ?))) + (pub (tcp-channel local-handle remote-handle ?)))