small change to registration format

This commit is contained in:
Matthias Felleisen 2011-03-27 13:54:22 -04:00
parent 5e7ac9a038
commit 8dbc1994bc

View File

@ -124,23 +124,22 @@
(read-line in) ;; read the newline
x))))
(define REGISTER '***register***)
(define OKAY '***okay***)
;; InPort OutPort (X -> Y) -> (U Y Void)
;; process a registration from a potential client, invoke k if it is okay
(define (tcp-process-registration in out k)
(define next (tcp-receive in))
(when (and (pair? next) (eq? REGISTER (car next)))
(tcp-send out OKAY)
(k (cdr next))))
(match next
[`(REGISTER ((name ,name)))
(tcp-send out '(OKAY))
(k name)]))
;; InPort OutPort (U #f String) -> Void
;; register with the server
(define (tcp-register in out name)
(tcp-send out `(,REGISTER ,(if name name (symbol->string (gensym 'world)))))
(unless (eq? (tcp-receive in) OKAY) (raise tcp-eof)))
(tcp-send out `(REGISTER ((name ,(if name name (symbol->string (gensym 'world)))))))
(define ackn (tcp-receive in))
(unless (equal? ackn '(OKAY))
(raise tcp-eof)))
;
;