aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIbrahim Mkusa <ibrahimmkusa@gmail.com>2017-04-16 13:50:26 -0400
committerIbrahim Mkusa <ibrahimmkusa@gmail.com>2017-04-16 13:50:26 -0400
commit52edc75849a97ba2cdee96ade120eaf14a90258c (patch)
treed947bb33d59e481538a0c32b891e564da2623604
parenta532a8cc71bd8e6522deed63237344a03768bafb (diff)
more readable names for some functions
-rw-r--r--Hermes/TODO11
-rw-r--r--Hermes/client.rkt5
-rw-r--r--Hermes/server.rkt27
3 files changed, 30 insertions, 13 deletions
diff --git a/Hermes/TODO b/Hermes/TODO
index 8135f57..0e41901 100644
--- a/Hermes/TODO
+++ b/Hermes/TODO
@@ -1,10 +1,13 @@
FEATURES
-4. message parsable?
-5. command parsable?
-8. separate main running code from definitions
+5. command(whisper, color, quit, count, users), message parsable?
16. plain tcp -> ssl based
17. fix breaks for improper disconnects from clients
18. Add topics after project completion
+** regexes to parse strings for different formats -related to 5
+** put into a list if necessary for manipulation
+
+** adjust sleep time on all to be 0.1 for more responsiveness
+** better function names
GOOD TO HAVE BUT NOT NECESSARY
7. maybe fiddle around with irc library (we leave this for future opl classes) no time got other classes
@@ -14,4 +17,6 @@ additionally save user details and prompt user to use defaults or create
new ones
10. authentication for databases - to avoid dependencies this is left out
11. user can ask for no of logged in users. - server already reports
+even the list of users connected.
+12. on connection server should also display list of users currently logged in
diff --git a/Hermes/client.rkt b/Hermes/client.rkt
index 3589765..c328095 100644
--- a/Hermes/client.rkt
+++ b/Hermes/client.rkt
@@ -16,6 +16,7 @@
(define host3 "localhost")
(define port-num 4321)
+; we won't need this. Just me being overzealous
(define hermes-conf (open-output-file "./hermes_client.conf" #:exists'append))
(define hermes-conf-s (make-semaphore 1))
@@ -39,6 +40,10 @@
(displayln "What's your name?")
(define username (read-line))
+ ;send the username to the server (username in out)
+ (displayln username out)
+ (flush-output out)
+
(define a (thread
(lambda ()
(displayln-safe "Starting receiver thread." error-out-s error-out)
diff --git a/Hermes/server.rkt b/Hermes/server.rkt
index ba2c1c2..aab2347 100644
--- a/Hermes/server.rkt
+++ b/Hermes/server.rkt
@@ -32,8 +32,8 @@
(define (make-connections connections)
(define (null-cons?)
(null? connections))
- (define (add in out)
- (set! connections (append connections (list (list in out))))
+ (define (add username in out)
+ (set! connections (append connections (list (list username in out))))
connections)
(define (cons-list)
connections)
@@ -86,7 +86,7 @@
(parameterize ([current-custodian main-cust])
(define listener (tcp-listen port-no 5 #t))
(define (loop)
- (accept-and-handle listener)
+ (receive-clients listener)
(loop))
(displayln-safe "Starting up the listener." error-out-s error-out)
(thread loop)
@@ -108,10 +108,17 @@
(semaphore-post convs-out-s)
(custodian-shutdown-all main-cust)))
-(define (accept-and-handle listener)
+(define (receive-clients listener)
(define cust (make-custodian))
(parameterize ([current-custodian cust])
(define-values (in out) (tcp-accept listener))
+
+ ;TODO retrive user name for client here
+ ; do some error checking
+ (define username-evt (read-line-evt out))
+
+
+
; increment number of connections
(semaphore-wait c-count-s)
((c-count 'increment))
@@ -126,12 +133,13 @@
(displayln-safe print-no-users convs-out-s convs-out)
(flush-output out)
(semaphore-wait connections-s)
- ((c-connections 'add) in out)
+ ; TODO add in a username so we have (username input output)
+ ((c-connections 'add) username-evt in out)
(semaphore-post connections-s)
; start a thread to deal with specific client and add descriptor value to the list of threads
(define threadcom (thread (lambda ()
- (handle in out)))) ; comms between server and particular client
+ (chat_with_client in out)))) ; comms between server and particular client
;; Watcher thread:
;; kills current thread for waiting too long for connection from
@@ -142,7 +150,7 @@
(sleep 1360)
(custodian-shutdown-all cust)))))
-(define (handle in out)
+(define (chat_with_client in out)
; deals with queueing incoming messages for server to broadcast to all clients
(define (something-to-say in)
(define evt-t0 (sync/timeout 60 (read-line-evt in 'linefeed)))
@@ -175,11 +183,11 @@
; extracts output port from a list pair of input and output port
(define (get-output-port ports)
- (cadr ports))
+ (caddr ports))
; extracts input port
(define (get-input-port ports)
- (car ports))
+ (cadr ports))
; broadcasts received message from clients periodically
; TODO before broadcasting the message make sure the ports is still open
@@ -199,6 +207,5 @@
(displayln "Message broadcasted"))])
(semaphore-post messages-s)))
-; TODO move to its own file
(define stop (serve 4321)) ;; start server then close with stop
(displayln-safe "Server process started\n" error-out-s error-out)