Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
;DEAL WITH: ; EMPTY ;CLEANUP: ; EMPTY ;POSSIBLE MESSAGES ;================= ;hello -- Used to initialize three-way handshake; client->server. ;welcome -- Lets client know server got "hello"; server->client. ;thanks -- Tells server that client is done logging in; client->server. ;goodbye -- Tells client that its connection to the server is gone; server->client. ;send-msg -- Informs server to send this message to another client; client->server. ;receive-msg -- Message to be received by client; server->client. ;logout -- Informs the server that the client is logging off; client->server. ;client-list -- List of clients logged into the server; server->client. (load "~cs61a/lib/im-common.scm") (define logging #t) ;clients variable stores all known clients. ;It's a table of entries in the format ("client name" . client-socket) (define clients-table (list '*table*)) ;Data abstraction for above: (define key car) (define value cdr) ;server variable stores the server socket (define server-socket #f) (define (add-client-to-table name sock) ;;;Add sock to the clients list bound to name ; ;Broadcasting the new client list is left up to other places in the code. ;This is done so as to function as the opposite to (remove-client-from-table). ; (if (not (assoc name (cdr clients-table))) (begin (set-cdr! clients-table (cons (cons name sock) (cdr clients-table))) #t) #f)) (define (remove-client-from-table name) ;;;Remove name from the clients list ; ;Broadcasting the new client list is left up to other places in the code. ;This is because if the server is shutting down the traffic created by ;sending a new client list after every remove client could be a issue. ; (define (helper who table) ;Remove key-value pair from table, return its value. (cond ((null? (cdr table)) #f) ((equal? who (key (cadr table))) (let ((result (value (cadr table)))) (set-cdr! table (cddr table))
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
result)) (else (helper who (cdr table))))) (let ((to-close-socket (helper name clients-table))) (if (not (socket-down? to-close-socket)) (begin (if (socket-input to-close-socket) (when-port-readable (socket-input to-close-socket) #f)) (socket-shutdown to-close-socket #f))))
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 6


This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online