examples/actor/chat-client.rkt

This commit is contained in:
Tony Garnock-Jones 2016-01-08 12:22:27 -05:00
parent a978731c55
commit 99466dad7f
1 changed files with 23 additions and 0 deletions

View File

@ -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)))))