From 99466dad7f3f2af701ad91a79ed0a60066f3e1dc Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Fri, 8 Jan 2016 12:22:27 -0500 Subject: [PATCH] examples/actor/chat-client.rkt --- prospect/examples/actor/chat-client.rkt | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 prospect/examples/actor/chat-client.rkt diff --git a/prospect/examples/actor/chat-client.rkt b/prospect/examples/actor/chat-client.rkt new file mode 100644 index 0000000..5a7cb97 --- /dev/null +++ b/prospect/examples/actor/chat-client.rkt @@ -0,0 +1,23 @@ +#lang prospect + +(require prospect/actor) +(require prospect/drivers/tcp) +(require (only-in racket/port read-bytes-line-evt)) + +(define local-handle (tcp-handle 'chat)) +(define remote-handle (tcp-address "localhost" 5999)) +(define stdin-evt (read-bytes-line-evt (current-input-port) 'any)) + +(actor-body->spawn-action + (lambda () + (perform-core-action! (spawn-tcp-driver)) + (forever (on (message (external-event stdin-evt (list $line)) #:meta-level 1) + (if (eof-object? line) + (return!) + (send! (tcp-channel local-handle remote-handle line)))) + + (assert (advertise (tcp-channel local-handle remote-handle _))) + (on (retracted (advertise (tcp-channel remote-handle local-handle _))) (return!)) + (on (message (tcp-channel remote-handle local-handle $bs)) + (write-bytes bs) + (flush-output)))))