2016-07-10 16:33:16 +00:00
|
|
|
#lang syndicate/actor
|
2016-01-08 17:22:27 +00:00
|
|
|
|
2016-07-30 17:02:07 +00:00
|
|
|
(require syndicate/protocol/advertise)
|
2016-07-12 19:05:56 +00:00
|
|
|
(require/activate syndicate/drivers/tcp)
|
2016-01-08 17:22:27 +00:00
|
|
|
(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))
|
|
|
|
|
2016-08-24 16:35:38 +00:00
|
|
|
(actor (stop-when (message (inbound (external-event stdin-evt (list (? eof-object? _))))))
|
|
|
|
(stop-when (retracted (advertise (tcp-channel remote-handle local-handle _))))
|
|
|
|
(assert (advertise (tcp-channel local-handle remote-handle _)))
|
2016-02-05 23:03:40 +00:00
|
|
|
|
2016-08-24 16:35:38 +00:00
|
|
|
(on (message (inbound (external-event stdin-evt (list (? bytes? $line)))))
|
|
|
|
(send! (tcp-channel local-handle remote-handle line)))
|
|
|
|
|
|
|
|
(on (message (tcp-channel remote-handle local-handle $bs))
|
|
|
|
(write-bytes bs)
|
|
|
|
(flush-output)))
|