2016-04-01 23:53:46 +00:00
|
|
|
#lang syndicate
|
2015-03-06 13:58:36 +00:00
|
|
|
|
2016-07-30 17:02:07 +00:00
|
|
|
(require syndicate/protocol/advertise)
|
2015-03-06 13:58:36 +00:00
|
|
|
(require (only-in racket/port read-bytes-line-evt))
|
2016-07-12 19:05:56 +00:00
|
|
|
(require/activate "../drivers/tcp.rkt")
|
2015-03-06 13:58:36 +00:00
|
|
|
|
|
|
|
(define local-handle (tcp-handle 'chat))
|
|
|
|
(define remote-handle (tcp-address "localhost" 5999))
|
|
|
|
|
2017-02-15 23:18:19 +00:00
|
|
|
(actor/stateless (lambda (e)
|
2015-03-06 13:58:36 +00:00
|
|
|
(match e
|
|
|
|
[(? patch/removed?) (quit)]
|
2016-07-30 17:02:07 +00:00
|
|
|
[(message (inbound (external-event _ (list (? eof-object?)))))
|
2015-03-06 13:58:36 +00:00
|
|
|
(quit)]
|
2016-07-30 17:02:07 +00:00
|
|
|
[(message (inbound (external-event _ (list line))))
|
2015-03-06 13:58:36 +00:00
|
|
|
(message (tcp-channel local-handle remote-handle line))]
|
|
|
|
[(message (tcp-channel _ _ bs))
|
|
|
|
(write-bytes bs)
|
|
|
|
(flush-output)
|
|
|
|
#f]
|
|
|
|
[_ #f]))
|
2015-12-03 20:53:07 +00:00
|
|
|
(patch-seq
|
2016-07-30 17:02:07 +00:00
|
|
|
(sub (inbound (external-event (read-bytes-line-evt (current-input-port) 'any) ?)))
|
2015-12-03 20:53:07 +00:00
|
|
|
(sub (tcp-channel remote-handle local-handle ?))
|
|
|
|
(sub (advertise (tcp-channel remote-handle local-handle ?)))
|
|
|
|
(pub (tcp-channel local-handle remote-handle ?))))
|