sleep delay interval setting now managed as a global variable

This commit is contained in:
Ibrahim Mkusa 2017-04-16 17:20:17 -04:00
parent 9e1f8c33d1
commit 7e7edb4a54
2 changed files with 6 additions and 4 deletions

View File

@ -15,6 +15,7 @@
(define host2 "67.186.191.81") (define host2 "67.186.191.81")
(define host3 "localhost") (define host3 "localhost")
(define port-num 4321) (define port-num 4321)
(define sleep-t 0.1)
; we won't need this. Just me being overzealous ; we won't need this. Just me being overzealous
(define hermes-conf (open-output-file "./hermes_client.conf" #:exists'append)) (define hermes-conf (open-output-file "./hermes_client.conf" #:exists'append))
@ -49,14 +50,14 @@
(displayln-safe "Starting receiver thread." error-out-s error-out) (displayln-safe "Starting receiver thread." error-out-s error-out)
(let loop [] (let loop []
(receive-messages in) (receive-messages in)
(sleep 1) (sleep sleep-t)
(loop))))) (loop)))))
(define t (thread (define t (thread
(lambda () (lambda ()
(displayln-safe "Starting sender thread." error-out-s error-out) (displayln-safe "Starting sender thread." error-out-s error-out)
(let loop [] (let loop []
(send-messages username out) (send-messages username out)
(sleep 1) (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

View File

@ -4,10 +4,11 @@
(require math/base) ;; for random number generation (require math/base) ;; for random number generation
;; globals
(define welcome-message "Welcome to Hermes coms. Type your message below") (define welcome-message "Welcome to Hermes coms. Type your message below")
(define successful-connection-m "Successfully connected to a client. Sending client a welcome message.") (define successful-connection-m "Successfully connected to a client. Sending client a welcome message.")
(define sleep-t 0.1)
; track number of connections with closure ; track number of connections with closure
(define (make-count no-count) (define (make-count no-count)
(define (increment) (define (increment)
@ -95,7 +96,7 @@
(thread (lambda () (thread (lambda ()
(displayln-safe "Broadcast thread started!\n") (displayln-safe "Broadcast thread started!\n")
(let loopb [] (let loopb []
(sleep 0.5) ;; wait 0.5 secs before beginning to broadcast (sleep sleep-t) ;; wait 0.5 secs before beginning to broadcast
(broadcast) (broadcast)
(loopb))))) (loopb)))))
(lambda () (lambda ()