aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIbrahim Mkusa <ibrahimmkusa@gmail.com>2017-04-12 13:49:20 -0400
committerIbrahim Mkusa <ibrahimmkusa@gmail.com>2017-04-12 13:49:20 -0400
commit4c26f1eaa3178bef2e69f38e63bd186e89c70381 (patch)
tree3c65ed9d26c2c423b36bd2ce64d2cebb0a54f29e
parent2899891a63adc7ddfdf212e00342bd297542552d (diff)
tidied up client.rkt. More stuff to TODO.txt
-rw-r--r--Hermes/TODO.txt2
-rw-r--r--Hermes/client.rkt39
2 files changed, 7 insertions, 34 deletions
diff --git a/Hermes/TODO.txt b/Hermes/TODO.txt
index d66b14a..02c421c 100644
--- a/Hermes/TODO.txt
+++ b/Hermes/TODO.txt
@@ -6,3 +6,5 @@
6. keep count of connected clients using object orientation
7. maybe fiddle around with irc library
8. separate main running code from definitions
+9. closure connections, messages, threads. Avoid using set! without an object
+ like make-account
diff --git a/Hermes/client.rkt b/Hermes/client.rkt
index 064db9e..db1a50c 100644
--- a/Hermes/client.rkt
+++ b/Hermes/client.rkt
@@ -4,15 +4,12 @@
;; author: Ibrahim Mkusa
;; about: print and read concurrently
;; notes: output may need to be aligned and formatted nicely
-;; look into
-;; https://docs.racket-lang.org/gui/text-field_.html#%28meth._%28%28%28lib._mred%2Fmain..rkt%29._text-field~25%29._get-editor%29%29
; custodian for client connections
(define main-client-cust (make-custodian))
; make connection to server
(define (client port-no)
-
(parameterize ([current-custodian main-client-cust])
;; connect to server at port 8080
(define-values (in out) (tcp-connect "localhost" port-no)) ;; define values
@@ -22,8 +19,6 @@
(displayln "What's your name?")
(define username (read-line))
- ; (thread (lambda ()
- ;; make threads 2 lines
(define a (thread
(lambda ()
(displayln "Starting receiver thread.")
@@ -46,37 +41,17 @@
(custodian-shutdown-all main-client-cust))
-;; the send-messages
+;; sends a message to the server
(define (send-messages username out)
;; intelligent read, quits when user types in "quit"
- ;(semaphore-wait fair)
- ; (display usernamei)
(define input (read-line))
- ;; do something over here with input maybe send it out
-
- ;; Tests input if its a quit then kills all threads
- ;; An if would be better here tbh
- ;; (cond ((string=? input "quit") (begin (kill-thread a)
- ;(kill-thread t))))
(cond ((string=? input "quit") (exit)))
- ;; modify to send messages to out port
(displayln (string-append username ": " input) out)
- (flush-output out)
+ (flush-output out))
- ;(semaphore-post fair)
- ; (read-loop-i out)
-)
-
-
-
-;; print hello world continously
-;; "(hello-world)" can be executed as part of background thread
-;; that prints in the event there is something in the input port
+; receives input from server and displays it to stdout
(define (receive-messages in)
- ; (sleep (random-integer 0 15)) ;; sleep between 0 and 15 seconds to simulate coms
- ;; with server
- ;(semaphore-wait fair)
- ;; we will retrieve the line printed below from the server
+ ; retrieve a message from server
(define evt (sync/timeout 60 (read-line-evt in)))
(cond [(eof-object? evt)
(displayln "Server connection closed.")
@@ -86,11 +61,7 @@
[(string? evt)
(displayln evt)] ; could time stamp here or to send message
[else
- (displayln (string-append "Nothing received from server for 2 minutes."))]
- )
- ;(semaphore-post fair)
-)
+ (displayln (string-append "Nothing received from server for 2 minutes."))]))
(define stop (client 4321))
(displayln "Client started.")
-