DOC PREVIEW
CMU CS 15213 - Recitation

This preview shows page 1-2-22-23 out of 23 pages.

Save
View full document
Premium Document
Do you want full access? Go Premium and unlock all 23 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

15213 Recitation Section C Shimin Chen Nov 25 2002 Outline Extending echo server HTTP Broken pipe error Feedback and evaluation Important Dates Lab 7 Proxy due on Thursday Dec 5 Final Exam Tuesday Dec 17 15213 Recitation C 2 Shimin Chen Extending Echo Server We will recap the echo client and server taught in the last lecture Then we will extend the echo server to build an echo proxy 15213 Recitation C 3 Shimin Chen An Echo Client Server Transaction Echo Client process 3 Client displays the text it receives 15213 Recitation C 1 Client sends an input line Echo Server process 2 Server sends the same text as it receives 4 Shimin Chen Review of the Sockets Interface Client Server socket socket bind open listenfd open clientfd connect Connection request listen accept rio writen rio readlineb rio readlineb rio writen close EOF Await connection request from next client rio readlineb close 15213 Recitation C 5 Shimin Chen Echo Client Main Routine include csapp h usage echoclient host port int main int argc char argv int clientfd port char host buf MAXLINE rio t rio host argv 1 port atoi argv 2 clientfd Open clientfd host port Rio readinitb rio clientfd while Fgets buf MAXLINE stdin NULL Rio writen clientfd buf strlen buf Rio readlineb rio buf MAXLINE Fputs buf stdout Close clientfd exit 0 15213 Recitation C 6 Shimin Chen Echo Client open clientfd int open clientfd char hostname int port This function opens a int clientfd connection from the client to struct hostent hp the server at hostname port struct sockaddr in serveraddr if clientfd socket AF INET SOCK STREAM 0 0 return 1 check errno for cause of error Fill in the server s IP address and port if hp gethostbyname hostname NULL return 2 check h errno for cause of error bzero char serveraddr sizeof serveraddr serveraddr sin family AF INET bcopy char hp h addr char serveraddr sin addr s addr hp h length serveraddr sin port htons port Establish a connection with the server if connect clientfd SA serveraddr sizeof serveraddr 0 return 1 return clientfd 15213 Recitation C 7 Shimin Chen Echo Server Main Routine int main int argc char argv int listenfd connfd port clientlen struct sockaddr in clientaddr struct hostent hp char haddrp port atoi argv 1 the server listens on a port passed on the command line listenfd open listenfd port while 1 clientlen sizeof clientaddr connfd Accept listenfd SA clientaddr clientlen hp Gethostbyaddr const char clientaddr sin addr s addr sizeof clientaddr sin addr s addr AF INET haddrp inet ntoa clientaddr sin addr printf server connected to s s n hp h name haddrp echo connfd Close connfd 15213 Recitation C 8 Shimin Chen Echo Server open listenfd int open listenfd int port int listenfd optval 1 struct sockaddr in serveraddr Create a socket descriptor if listenfd socket AF INET SOCK STREAM 0 0 return 1 Eliminates Address already in use error from bind if setsockopt listenfd SOL SOCKET SO REUSEADDR const void optval sizeof int 0 return 1 more 15213 Recitation C 9 Shimin Chen Echo Server open listenfd cont Listenfd will be an endpoint for all requests to port on any IP address for this host bzero char serveraddr sizeof serveraddr serveraddr sin family AF INET serveraddr sin addr s addr htonl INADDR ANY serveraddr sin port htons unsigned short port if bind listenfd SA serveraddr sizeof serveraddr 0 return 1 Make it a listening socket ready to accept connection requests if listen listenfd LISTENQ 0 return 1 return listenfd 15213 Recitation C 10 Shimin Chen Echo Server echo void echo int connfd size t n char buf MAXLINE rio t rio Rio readinitb rio connfd while n Rio readlineb rio buf MAXLINE 0 printf server received d bytes n n Rio writen connfd buf n 15213 Recitation C 11 Shimin Chen Proxy A proxy is an intermediary between a client and an origin server To the client the proxy acts like a server To the server the proxy acts like a client Echo proxy process Echo Client process 15213 Recitation C 12 Echo Server process Shimin Chen Changing echo procedure void echo forward int connfd char server int server port int forwardfd rio t rio conn rio forward ssize t n char buf MAXLINE connect to the server forwardfd Open clientfd server server port Rio readinitb rio forward forwardfd Rio readinitb rio conn connfd while 1 if n Rio readlineb rio conn buf MAXLINE 0 break Rio writen forwardfd buf n if n Rio readlineb rio forward buf MAXLINE 0 break Rio writen connfd buf n Close forwardfd 15213 Recitation C 13 Shimin Chen Changing main int main int argc char argv int listenfd connfd port clientlen server port struct sockaddr in clientaddr struct hostent hp char haddrp server port atoi argv 1 server argv 2 server port atoi argv 3 listenfd Open listenfd port while 1 clientlen sizeof clientaddr connfd Accept listenfd SA clientaddr clientlen echo forward connfd server server port Close connfd exit 0 15213 Recitation C 14 Shimin Chen L7 Proxy Different request and response HTTP Concurrency 15213 Recitation C Echo Client process Echo proxy process Echo Server process Web Browser process Web proxy process Web Server process 15 Shimin Chen HTTP Request and Response Let s use telnet to examine a simple HTTP request and response More details in Tuesday s lecture 15213 Recitation C 16 Shimin Chen HTTP Request and Response chensm bass telnet www cmu edu 80 Trying 128 2 11 43 Connected to WEB3 andrew cmu edu Escape character is GET HTTP 1 1 host www cmu edu HTTP 1 1 200 OK Date Sun 24 Nov 2002 21 52 53 GMT Server Apache 1 3 26 Unix PHP 4 2 2 mod pubcookie a5 1 76 009 mod ssl 2 8 10 OpenSSL 0 9 6d Last Modified Thu 21 Nov 2002 15 28 47 GMT ETag d3226 38b1 3ddcfbaf Accept Ranges bytes Content Length 14513 Content Type text html HTML HEAD TITLE Carnegie Mellon University TITLE HEAD 15213 Recitation C 17 Shimin Chen HTTP Request Request line method uri version GET HTTP 1 1 host www cmu edu Request headers header name header data r n to mark the end of the request 15213 Recitation C 18 Shimin Chen HTTP Response Response line version status code status msg Response headers header name header data HTTP 1 1 200 OK Date Sun 24 Nov 2002 21 52 53 GMT Server Apache 1 3 26 Unix PHP 4 2 2 mod pubcookie a5 1 76 009 mod ssl 2 8 10 OpenSSL 0 9 6d Last Modified Thu 21 Nov 2002 15 28 47 GMT ETag d3226 38b1 3ddcfbaf Accept Ranges bytes Content Length 14513 Content Type text html r n Response body Web page HTML HEAD TITLE Carnegie Mellon University TITLE HEAD 15213 Recitation C 19 Shimin Chen Broken Pipe Error When reading or writing to a socket If the socket has


View Full Document

CMU CS 15213 - Recitation

Documents in this Course
lecture

lecture

14 pages

lecture

lecture

46 pages

Caches

Caches

9 pages

lecture

lecture

39 pages

Lecture

Lecture

36 pages

Lecture

Lecture

45 pages

Lecture

Lecture

56 pages

lecture

lecture

11 pages

lecture

lecture

9 pages

Lecture

Lecture

36 pages

Lecture

Lecture

37 pages

Exam

Exam

16 pages

Lecture

Lecture

10 pages

Lecture

Lecture

43 pages

Lecture

Lecture

8 pages

Lecture

Lecture

8 pages

Lecture

Lecture

36 pages

Lecture

Lecture

43 pages

Lecture

Lecture

12 pages

Lecture

Lecture

37 pages

Lecture

Lecture

6 pages

Lecture

Lecture

40 pages

coding

coding

2 pages

Exam

Exam

17 pages

Exam

Exam

14 pages

Lecture

Lecture

29 pages

Lecture

Lecture

34 pages

Exam

Exam

11 pages

Lecture

Lecture

9 pages

Lecture

Lecture

37 pages

Lecture

Lecture

36 pages

lecture

lecture

46 pages

Lecture

Lecture

33 pages

Lecture

Lecture

57 pages

Lecture

Lecture

32 pages

Lecture

Lecture

46 pages

Lecture

Lecture

40 pages

Lecture

Lecture

11 pages

Lecture

Lecture

6 pages

Lecture

Lecture

43 pages

Lecture

Lecture

12 pages

Lecture

Lecture

18 pages

Exam

Exam

10 pages

Lecture

Lecture

45 pages

Lecture

Lecture

37 pages

Exam

Exam

24 pages

class09

class09

21 pages

class22

class22

37 pages

class20

class20

30 pages

class27

class27

33 pages

class25

class25

21 pages

class04

class04

31 pages

Lecture

Lecture

59 pages

class01a

class01a

14 pages

class12

class12

45 pages

class29

class29

33 pages

Lecture

Lecture

39 pages

Lecture

Lecture

6 pages

class03

class03

34 pages

lecture

lecture

42 pages

Lecture

Lecture

40 pages

Lecture

Lecture

47 pages

Exam

Exam

19 pages

R06-B

R06-B

25 pages

class17

class17

37 pages

class25

class25

31 pages

Lecture

Lecture

15 pages

final-f06

final-f06

17 pages

Lecture

Lecture

9 pages

lecture

lecture

9 pages

Exam

Exam

15 pages

Lecture

Lecture

22 pages

class11

class11

45 pages

lecture

lecture

50 pages

Linking

Linking

37 pages

Lecture

Lecture

64 pages

Integers

Integers

40 pages

Exam

Exam

11 pages

Lecture

Lecture

37 pages

Lecture

Lecture

44 pages

Lecture

Lecture

37 pages

Lecture

Lecture

9 pages

Lecture

Lecture

37 pages

Lecture

Lecture

45 pages

Final

Final

25 pages

lecture

lecture

9 pages

Lecture

Lecture

30 pages

Lecture

Lecture

16 pages

Final

Final

17 pages

Lecture

Lecture

8 pages

Exam

Exam

11 pages

Lecture

Lecture

47 pages

Lecture

Lecture

9 pages

lecture

lecture

39 pages

Exam

Exam

11 pages

lecture

lecture

41 pages

lecture

lecture

37 pages

Lecture

Lecture

59 pages

Lecture

Lecture

45 pages

Exam 1

Exam 1

18 pages

Lecture

Lecture

41 pages

Lecture

Lecture

32 pages

Lecture

Lecture

30 pages

Lecture

Lecture

9 pages

Lecture

Lecture

9 pages

Lecture

Lecture

15 pages

Lecture

Lecture

11 pages

Lecture

Lecture

9 pages

Lecture

Lecture

34 pages

Lecture

Lecture

40 pages

Lecture

Lecture

4 pages

Lecture

Lecture

46 pages

Lecture

Lecture

8 pages

Lecture

Lecture

65 pages

Lecture

Lecture

38 pages

Lecture

Lecture

35 pages

Lecture

Lecture

8 pages

Lecture

Lecture

34 pages

Lecture

Lecture

8 pages

Exam

Exam

13 pages

Lecture

Lecture

43 pages

Lecture

Lecture

9 pages

Lecture

Lecture

12 pages

Lecture

Lecture

9 pages

Lecture

Lecture

34 pages

Lecture

Lecture

43 pages

Lecture

Lecture

7 pages

Lecture

Lecture

45 pages

Lecture

Lecture

24 pages

Lecture

Lecture

47 pages

Lecture

Lecture

12 pages

Lecture

Lecture

20 pages

Lecture

Lecture

9 pages

Exam

Exam

11 pages

Lecture

Lecture

52 pages

Lecture

Lecture

20 pages

Exam

Exam

11 pages

Lecture

Lecture

35 pages

Lecture

Lecture

47 pages

Lecture

Lecture

18 pages

Lecture

Lecture

30 pages

Lecture

Lecture

59 pages

Lecture

Lecture

37 pages

Lecture

Lecture

22 pages

Lecture

Lecture

35 pages

Exam

Exam

23 pages

Lecture

Lecture

9 pages

Lecture

Lecture

22 pages

class12

class12

32 pages

Lecture

Lecture

8 pages

Lecture

Lecture

39 pages

Lecture

Lecture

44 pages

Lecture

Lecture

38 pages

Lecture

Lecture

69 pages

Lecture

Lecture

41 pages

Lecture

Lecture

12 pages

Lecture

Lecture

52 pages

Lecture

Lecture

59 pages

Lecture

Lecture

39 pages

Lecture

Lecture

83 pages

Lecture

Lecture

59 pages

class01b

class01b

17 pages

Exam

Exam

21 pages

class07

class07

47 pages

Lecture

Lecture

11 pages

Odyssey

Odyssey

18 pages

multicore

multicore

66 pages

Lecture

Lecture

6 pages

lecture

lecture

41 pages

lecture

lecture

55 pages

lecture

lecture

52 pages

lecture

lecture

33 pages

lecture

lecture

46 pages

lecture

lecture

55 pages

lecture

lecture

17 pages

lecture

lecture

49 pages

Exam

Exam

17 pages

lecture

lecture

56 pages

Exam 2

Exam 2

16 pages

Exam 2

Exam 2

16 pages

Notes

Notes

37 pages

Lecture

Lecture

40 pages

Lecture

Lecture

36 pages

Lecture

Lecture

43 pages

Lecture

Lecture

25 pages

Exam

Exam

13 pages

Lecture

Lecture

32 pages

Lecture

Lecture

12 pages

Lecture

Lecture

58 pages

Lecture

Lecture

29 pages

Lecture

Lecture

59 pages

Lecture

Lecture

41 pages

Lecture

Lecture

50 pages

Exam

Exam

17 pages

Lecture

Lecture

29 pages

Lecture

Lecture

44 pages

Lecture

Lecture

41 pages

Lecture

Lecture

52 pages

Lecture

Lecture

40 pages

Lecture

Lecture

33 pages

lecture

lecture

10 pages

Lecture

Lecture

27 pages

Lecture

Lecture

29 pages

Lecture

Lecture

39 pages

Lecture

Lecture

9 pages

Lecture

Lecture

29 pages

Lecture

Lecture

8 pages

Lecture

Lecture

43 pages

Lecture

Lecture

43 pages

Lecture

Lecture

75 pages

Lecture

Lecture

55 pages

Exam

Exam

12 pages

Lecture

Lecture

43 pages

Lecture

Lecture

35 pages

lecture

lecture

36 pages

Exam

Exam

33 pages

lecture

lecture

56 pages

lecture

lecture

64 pages

lecture

lecture

8 pages

Exam

Exam

14 pages

Lecture

Lecture

43 pages

Lecture

Lecture

36 pages

lecture

lecture

56 pages

lecture

lecture

75 pages

lecture

lecture

36 pages

Lecture

Lecture

50 pages

Lecture

Lecture

45 pages

Lecture

Lecture

13 pages

Exam

Exam

23 pages

Lecture

Lecture

10 pages

Lecture

Lecture

48 pages

Lecture

Lecture

83 pages

lecture

lecture

57 pages

Lecture

Lecture

33 pages

Lecture

Lecture

39 pages

Lecture

Lecture

33 pages

lecture

lecture

54 pages

Lecture

Lecture

30 pages

Exam

Exam

13 pages

Lecture

Lecture

36 pages

Lecture

Lecture

40 pages

Exam

Exam

17 pages

Lecture

Lecture

9 pages

Exam

Exam

15 pages

Lecture

Lecture

44 pages

Lecture

Lecture

34 pages

Lecture

Lecture

24 pages

Lecture

Lecture

29 pages

class12

class12

43 pages

lecture

lecture

43 pages

class22

class22

22 pages

R06-B

R06-B

25 pages

class01b

class01b

19 pages

lecture

lecture

29 pages

lab1

lab1

8 pages

Caches

Caches

36 pages

lecture

lecture

55 pages

Lecture,

Lecture,

37 pages

Integers

Integers

40 pages

Linking

Linking

38 pages

lecture

lecture

45 pages

Lecture

Lecture

61 pages

Linking

Linking

33 pages

lecture

lecture

40 pages

lecture

lecture

40 pages

Lecture

Lecture

32 pages

lecture

lecture

48 pages

lecture

lecture

44 pages

Exam

Exam

11 pages

Lecture

Lecture

31 pages

Lecture

Lecture

46 pages

Lecture

Lecture

40 pages

Lecture

Lecture

40 pages

Exam

Exam

12 pages

Lecture

Lecture

42 pages

Lecture

Lecture

36 pages

Lecture

Lecture

45 pages

Lecture

Lecture

41 pages

Lecture

Lecture

13 pages

Lecture

Lecture

35 pages

Lecture

Lecture

20 pages

Final

Final

19 pages

Lecture

Lecture

33 pages

Lecture

Lecture

50 pages

Lecture

Lecture

33 pages

Lecture

Lecture

27 pages

Lecture

Lecture

6 pages

Exam

Exam

15 pages

Lecture

Lecture

24 pages

Lecture

Lecture

23 pages

Lecture

Lecture

43 pages

Lecture

Lecture

32 pages

Lecture

Lecture

52 pages

Lecture

Lecture

37 pages

Lecture

Lecture

36 pages

Lecture

Lecture

34 pages

Lecture

Lecture

40 pages

Lecture

Lecture

15 pages

lecture

lecture

21 pages

Lecture

Lecture

58 pages

Lecture

Lecture

49 pages

Lecture

Lecture

36 pages

Lecture

Lecture

11 pages

Lecture

Lecture

12 pages

Lecture

Lecture

58 pages

Lecture

Lecture

33 pages

Exam

Exam

15 pages

Lecture

Lecture

35 pages

Lecture

Lecture

10 pages

Lecture

Lecture

25 pages

Lecture

Lecture

31 pages

Lecture

Lecture

24 pages

Lecture

Lecture

34 pages

Lecture

Lecture

50 pages

lecture

lecture

35 pages

Lecture

Lecture

11 pages

Lecture

Lecture

39 pages

Lecture

Lecture

45 pages

Lecture

Lecture

41 pages

exam1-f05

exam1-f05

11 pages

Lecture

Lecture

4 pages

Lecture

Lecture

17 pages

Exam

Exam

17 pages

malloc()

malloc()

12 pages

Lecture

Lecture

57 pages

Lecture

Lecture

30 pages

Lecture

Lecture

30 pages

Lecture

Lecture

47 pages

Lecture

Lecture

33 pages

Exam

Exam

12 pages

Lecture

Lecture

43 pages

Lectures

Lectures

33 pages

Lecture

Lecture

36 pages

lecture

lecture

33 pages

Exam

Exam

14 pages

Lecture

Lecture

43 pages

Lecture

Lecture

25 pages

Load more
Download Recitation
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Recitation and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Recitation and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?