messages from other clients now display on the GUI

This commit is contained in:
Ibrahim Mkusa 2017-04-23 02:52:39 -04:00
parent 29c6708e13
commit a1798d9e3d
2 changed files with 25 additions and 7 deletions

View File

@ -10,9 +10,9 @@
;; notes: output may need to be aligned and formatted nicely ;; notes: output may need to be aligned and formatted nicely
; we will prompt for these in the gui
(define hermes-gui (make-gui)) ;; our gui (define hermes-gui (make-gui)) ;; our gui
((hermes-gui 'show)) ((hermes-gui 'show))
(sleep 0.25)
(define host3 "localhost") (define host3 "localhost")
@ -44,6 +44,10 @@
; TODO ; TODO
; semaphore for gui object ; semaphore for gui object
; could display a bubble and prompt for username in GUI object ; could display a bubble and prompt for username in GUI object
; create a gui object
; (define hermes-gui (make-gui))
; ((hermes-gui 'show))
(displayln "What's your name?") (displayln "What's your name?")
(define username (read-line)) (define username (read-line))
@ -66,11 +70,14 @@
(sleep sleep-t) (sleep sleep-t)
(loop))))) (loop)))))
(displayln-safe "Now waiting for sender thread." error-out-s error-out) (displayln-safe "Now waiting for sender thread." error-out-s error-out)
(thread-wait t) ;; returns prompt back to drracket ; (thread-wait t) ;; returns prompt back to drracket
)
(lambda ()
(displayln-safe "Closing client ports." error-out-s error-out) (displayln-safe "Closing client ports." error-out-s error-out)
(close-input-port in) ;(close-input-port in)
(close-output-port out)) ;(close-output-port out)
(custodian-shutdown-all main-client-cust)) (custodian-shutdown-all main-client-cust)))
;; sends a message to the server ;; sends a message to the server
@ -85,6 +92,7 @@
(number->string (date-second date-today)) (number->string (date-second date-today))
" | ")) " | "))
;; read, quits when user types in "quit" ;; read, quits when user types in "quit"
;; TODO read from GUI instead
(define input (read-line)) (define input (read-line))
; TODO /quit instead of quit ; TODO /quit instead of quit
(cond ((string=? input "quit") (cond ((string=? input "quit")
@ -97,6 +105,11 @@
(displayln (string-append date-print username ": " input) out) (displayln (string-append date-print username ": " input) out)
(flush-output out)) (flush-output out))
; sigh why you do this racket
(define send-to-gui
(lambda (message color)
((hermes-gui 'send) message color)))
; receives input from server and displays it to stdout ; receives input from server and displays it to stdout
(define (receive-messages in) (define (receive-messages in)
; retrieve a message from server ; retrieve a message from server
@ -109,9 +122,13 @@
] ]
[(string? evt) [(string? evt)
(displayln-safe evt convs-out-s convs-out) (displayln-safe evt convs-out-s convs-out)
((hermes-gui 'send) evt "black")] ; could time stamp here or to send message (send-to-gui evt "black")
] ; could time stamp here or to send message
[else [else
(displayln-safe (string-append "Nothing received from server for 2 minutes.") convs-out-s convs-out)])) (displayln-safe (string-append "Nothing received from server for 2 minutes.") convs-out-s convs-out)]))
(displayln-safe "Starting client." error-out-s error-out) (displayln-safe "Starting client." error-out-s error-out)
(define stop-client (client 4321)) (define stop-client (client 4321))
;(define stop-client (client 4321))
; we will prompt for these in the gui

View File

@ -186,6 +186,7 @@
(define list-count (regexp-match #px"(.*)/list\\s+count\\s*" evt-t0)) ;; is client asking for number of logged in users (define list-count (regexp-match #px"(.*)/list\\s+count\\s*" evt-t0)) ;; is client asking for number of logged in users
(define list-users (regexp-match #px"(.*)/list\\s+users\\s*" evt-t0)) ;; user names (define list-users (regexp-match #px"(.*)/list\\s+users\\s*" evt-t0)) ;; user names
; do something whether it was a message, a whisper, request for number of users and so on ; do something whether it was a message, a whisper, request for number of users and so on
; TODO if user doesn't exist handle it
(cond [whisper (cond [whisper
(semaphore-wait connections-s) (semaphore-wait connections-s)
; get output port for user ; get output port for user