#lang syndicate ;;; SPDX-License-Identifier: LGPL-3.0-or-later ;;; SPDX-FileCopyrightText: Copyright © 2023 Tony Garnock-Jones (module+ main (require syndicate/distributed/gatekeeper) (require syndicate/distributed/tcp) (require syndicate/driver-support) (require syndicate/gensym) (require "schemas/simpleChatProtocol.rkt") (require syndicate/sturdy) (require (only-in file/sha1 hex-string->bytes)) (define me (symbol->string (strong-gensym 'user))) (define ref (SturdyRef "syndicate" '() (hex-string->bytes "a6480df5306611ddd0d3882b546e1977"))) (standard-actor-system (ds) (define conn-facet this-facet) (define (on-connected remote-ds) (on-stop (stop-facet conn-facet)) (linked-thread #:name (list 'read-stdin) (lambda (facet) (let loop () (match (read-line) [(? eof-object?) (log-info "EOF on stdin.")] [line (turn! facet (lambda () (send! remote-ds (Says me line)))) (loop)])))) (at remote-ds (assert (Present me)) (during (Present $who) (on-start (log-info "~a arrived" who)) (on-stop (log-info "~a departed" who))) (on (message (Says $who $what)) (log-info "~a says: ~v" who what)))) (run-tcp-client-relay ds #:hostname "localhost" #:port 8001 #:import (lambda (v) (gatekeeper-resolve (embedded-value v) ref on-connected)))))