Clients can now talk with each other
This commit is contained in:
parent
2f0d04ce7f
commit
69523cc2ed
3
Hermes/Makefile
Normal file
3
Hermes/Makefile
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# Remove idiotic save files
|
||||||
|
clean:
|
||||||
|
rm -rf *~
|
@ -139,22 +139,48 @@
|
|||||||
'ok
|
'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 a broadcast function
|
||||||
(define broadcast
|
(define broadcast
|
||||||
(lambda ()
|
(lambda ()
|
||||||
(semaphore-wait messages-s)
|
(semaphore-wait messages-s)
|
||||||
(semaphore-wait threads-s)
|
|
||||||
(if (not (null? messages))
|
(if (not (null? messages))
|
||||||
(begin (map (lambda (thread-descriptor)
|
(begin (map
|
||||||
(thread-send thread-descriptor (first messages)))
|
(lambda (ports)
|
||||||
threads)
|
(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))
|
(set! messages (rest messages))
|
||||||
(displayln "Broadcasted a message\n")
|
;; current state of messages and connections
|
||||||
)
|
messages
|
||||||
(display "No message to display\n") ; for later create file port for errors and save error messages to that file
|
connections)
|
||||||
)
|
(display "No message to display\n"))
|
||||||
messages ; whats the current state of messages
|
; Approach one was to broadcast via thread mailboxes
|
||||||
(semaphore-post threads-s)
|
;(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)))
|
(semaphore-post messages-s)))
|
||||||
|
|
||||||
(define stop (serve 4321)) ;; start server then close with stop
|
(define stop (serve 4321)) ;; start server then close with stop
|
||||||
|
Loading…
Reference in New Issue
Block a user