2021-06-11 13:29:12 +00:00
|
|
|
#lang syndicate
|
|
|
|
;;; SPDX-License-Identifier: LGPL-3.0-or-later
|
2022-01-16 08:48:18 +00:00
|
|
|
;;; SPDX-FileCopyrightText: Copyright © 2021-2022 Tony Garnock-Jones <tonyg@leastfixedpoint.com>
|
2021-06-11 13:29:12 +00:00
|
|
|
|
|
|
|
(module+ main
|
|
|
|
(require racket/cmdline)
|
|
|
|
(require syndicate/drivers/tcp)
|
|
|
|
|
|
|
|
(define host "0.0.0.0")
|
|
|
|
(define port 5999)
|
|
|
|
|
|
|
|
(command-line #:once-each
|
|
|
|
[("--host" "-H") hostname "Set hostname to listen on"
|
|
|
|
(set! host hostname)]
|
|
|
|
[("--port" "-p") port-number "Set port number to listen on"
|
|
|
|
(set! port (string->number port-number))])
|
|
|
|
|
|
|
|
(message-struct Line (text))
|
|
|
|
|
2021-06-17 12:57:06 +00:00
|
|
|
(standard-actor-system (ds)
|
|
|
|
(at ds
|
2021-06-18 11:48:12 +00:00
|
|
|
(stop-on (asserted (StreamListenerError (TcpLocal host port) $message)))
|
2021-06-17 12:57:06 +00:00
|
|
|
(during/spawn (StreamConnection $source $sink (TcpLocal host port))
|
|
|
|
(handle-connection source sink
|
|
|
|
#:initial-mode (Mode-lines (LineMode-lf))
|
|
|
|
#:on-data (lambda (data mode) (send! ds (Line data))))
|
|
|
|
(at ds (on (message (Line $data)) (send-line sink data)))))))
|