lecture22 - C LIENT-S ERVER P ARADIGM , M AP R EDUCE 22...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: C LIENT-S ERVER P ARADIGM , M AP R EDUCE 22 GEORGE WANG gswang.cs61a@gmail.com Department of Electrical Engineering and Computer Sciences University of California, Berkeley July 29, 2010 1 Threads, Callbacks (define (im-server-start) ;;;Start the server. ; ;Set! server-socket variable ;Set thunk for handling handshake with new client ; (format logging "~%Server starting...~%") (set! server-socket (make-server-socket)) (format #t "Server IP address: ~A, server port: ~A~%" (get-ip-address-as-string) (socket-port-number server-socket)) ( when-socket-ready server-socket (lambda () (begin (format logging "New client connecting.~%") (handshake (socket-dup server-socket))))) (format logging "(im-server-start) done.~%~%") okay) 2 The 3-Way Handshake (define (handshake sock) ;;;Handle the three-way handshake with a client. ; ;Handshaking should go as follows: 1 ;client->server: ; request from CLIENT to server with request "hello" and data nil ;server->client: ; request from server to CLIENT with request "welcome" and data nil ;client->server: ; request from CLIENT to server with request "thanks" and data nil ; ;;Accept the socket connection (socket-accept-connection sock) (format logging "Connection accepted for ~A...~%" sock) (let * ((port-from-client (socket-input sock)) (port-to-client (socket-output sock)) (req (get-request port-from-client))) (if (not req) (socket-shutdown sock #f) (begin (format logging "Request received: ~S~%" req) ;; Check message is " hello ". (cond ((not (equal? hello (request-action req))) (format #t "Bad request from client: ~S" req) (socket-shutdown sock #f)) ((member (request-src req) (get-clients-list)) ;; name already exists, send "sorry" to client (format logging "Sending sorry to client~%") (send-request (make-request server (request-src req) sorry nil) port-to-client) (format #t "Name ~A already exists." (request-src req)) (socket-shutdown sock #f)) (else ;;Send " welcome " message back. (format logging "Sending welcome message.~%") (if (not (send-request (make-request server (request-src req) welcome nil) port-to-client)) (socket-shutdown sock #f) (begin ;; Check response is " thanks " (set! req (get-request port-from-client)) (if (not req) (socket-shutdown sock #f) (begin 2 (format logging "Response received: ~S~%" req) (if (not (equal? thanks (request-action req))) (begin (format #t "Bad response from client: ~S" req) (socket-shutdown sock #f)) (begin ;; Finally, we can register the client (format logging "~A has logged on.~%" (request-src req)) (register-client (request-src req) sock) (format logging "Finished handshake~%") )) ) ))))) ))) okay) 3 MapReduce Heres the diagram of mapreduce again: ACCUMULATE MAP kv kv kv kv kv kv key REDUCE key REDUCE REDUCE key key key key (mapreduce f1 f2 base dataname) f1 f2 () MAP MAP MAP MAP SORT value value value value value value result result result f1 f2 (accumulate f2 base (map f1 data)) The seemingly unpoetic names f1 and f2 serve to remind you of two things:...
View Full Document

This note was uploaded on 08/14/2010 for the course EECS 61A taught by Professor Harvey during the Summer '08 term at University of California, Berkeley.

Page1 / 6

lecture22 - C LIENT-S ERVER P ARADIGM , M AP R EDUCE 22...

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

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