examples/actor/chat-client.rkt
This commit is contained in:
parent
a978731c55
commit
99466dad7f
|
@ -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)))))
|
Loading…
Reference in New Issue