diff options
author | Ibrahim Mkusa <ibrahimmkusa@gmail.com> | 2017-04-12 00:01:52 -0400 |
---|---|---|
committer | Ibrahim Mkusa <ibrahimmkusa@gmail.com> | 2017-04-12 00:01:52 -0400 |
commit | 69523cc2ed211285468148d835c320447f21fc04 (patch) | |
tree | ede195905f8d9591f2b8ab6b516db765b3f4e088 | |
parent | 2f0d04ce7febc3617a8bc0e7bb3fa2a823ae78da (diff) |
Clients can now talk with each other
-rw-r--r-- | Hermes/Makefile | 3 | ||||
-rw-r--r-- | Hermes/server.rkt | 46 |
2 files changed, 39 insertions, 10 deletions
diff --git a/Hermes/Makefile b/Hermes/Makefile new file mode 100644 index 0000000..eda5bbb --- /dev/null +++ b/Hermes/Makefile @@ -0,0 +1,3 @@ +# Remove idiotic save files +clean: + rm -rf *~ diff --git a/Hermes/server.rkt b/Hermes/server.rkt index 541024e..c57fbe7 100644 --- a/Hermes/server.rkt +++ b/Hermes/server.rkt @@ -139,22 +139,48 @@ 'ok ) +;; a bunch of selectors, predicates for connections +(define (get-output-port ports) + (cadr ports) + ) + +(define (get-input-port ports) + (car ports) +) ;; define a broadcast function (define broadcast (lambda () (semaphore-wait messages-s) - (semaphore-wait threads-s) + (if (not (null? messages)) - (begin (map (lambda (thread-descriptor) - (thread-send thread-descriptor (first messages))) - threads) + (begin (map + (lambda (ports) + (displayln (first messages) (get-output-port ports)) + (flush-output (get-output-port ports)) + ;; log message to server + (displayln "Message sent") + ) + connections) + ;; remove top message (set! messages (rest messages)) - (displayln "Broadcasted a message\n") - ) - (display "No message to display\n") ; for later create file port for errors and save error messages to that file - ) - messages ; whats the current state of messages - (semaphore-post threads-s) + ;; current state of messages and connections + messages + connections) + (display "No message to display\n")) + ; Approach one was to broadcast via thread mailboxes + ;(semaphore-wait threads-s) + ;(if (not (null? messages)) + ; (begin (map (lambda (thread-descriptor) + ; (thread-send thread-descriptor (first messages))) + ; threads) + ; (set! messages (rest messages)) + ; (displayln "Broadcasted a message\n") + ;) + ;(display "No message to display\n") ; for later create file port for errors and save error messages to that file + ;) + ; messages ; whats the current state of messages + ;(semaphore-post threads-s) + (semaphore-post messages-s))) (define stop (serve 4321)) ;; start server then close with stop |