more readable names for some functions

This commit is contained in:
Ibrahim Mkusa 2017-04-16 13:50:26 -04:00
parent a532a8cc71
commit 52edc75849
3 changed files with 30 additions and 13 deletions

View File

@ -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

View File

@ -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)

View File

@ -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)