Extending echo server HTTP Broken pipe error Feedback and evaluation

Slides:



Advertisements
Similar presentations
Network Programming Topics Peeking at Internet traffic Programmer’s view of the Internet (review) Sockets interface Writing clients and servers Understanding.
Advertisements

Chris Riesbeck, Fall 2007 Network Programming Topics –Sockets interface –Writing clients and servers.
Socket Programming Application Programming Interface.
Carnegie Mellon 1 Network Programming : Introduction to Computer Systems 20 th Lecture, Nov. 2, 2010 Instructors: Randy Bryant and Dave O’Hallaron.
Network Programming Topics Sockets interface Writing clients and servers CS 105 “Tour of the Black Holes of Computing!”
Networks and Network Programming May 24, 2006 Topics Client-server programming model Networks A programmer’s view of the Internet Sockets interface Writing.
– 1 – CS213, S’08 Network Programming June 4, 2008 Topics Sockets interface Writing clients and servers.
Network Programming November 19, 2007 Topics Peeking at Internet traffic Programmer’s view of the Internet (review) Sockets interface Writing clients and.
Network Programming Nov. 6, 2008 Topics Peeking at Internet traffic Programmer’s view of the Internet (review) Sockets interface Writing clients and servers.
Network Programming Nov 21, 2002 Topics Programmer’s view of the Internet (review) Sockets interface Writing clients and servers class26.ppt “The.
1 Example (UDP Client) // This program sends UDP packets to the given address #include #define SERVER_ADDR " " #define SERVER_PORT 5555 void error(char.
Internetworking II: Network programming April 20, 2000 Topics client/server model Berkeley sockets –TCP client and server examples –UDP client and server.
Networking S04, Recitation, Section A
1. Networks and the Internet 2. Network programming.
Recitation 12: 11/25/02 Outline Socket Interface –Echo Client/Server Http Protocol Evaluation Annie Luo Office Hours: Thursday.
Networking Alan L. Cox T. S. Eugene Ng Some slides adapted from CMU slides.
University of Amsterdam Computer Systems – Iterative server Arnoud Visser 1 Computer Systems Iterative server.
Computer Systems II CSC 2405 Network Programming.
INTERNET L4: Internet. Last Lecture Re-cap: IP Internet  Based on the TCP/IP protocol family  IP (Internet protocol) : Provides basic naming scheme.
Network Programming Topics Programmer’s view of the Internet Sockets interface Writing clients and servers CS 105 “Tour of the Black Holes of Computing!”
Recitation 12 (Nov. 29) Outline Socket programming Lab 7: part 1 Reminder Lab 7: Due next Thursday Minglong Shao Office hours: Thursdays.
1 Concurrent Programming. 2 Outline Concurrent programming –Processes –Threads Suggested reading: –12.1, 12.3.
Carnegie Mellon 1 Network Programming / : Introduction to Computer Systems 21 st Lecture, Nov. 7, 2013 Instructors: Randy Bryant, Dave O’Hallaron,
Network Programming September 6, 2005 Topics Programmer’s view of the Internet Sockets interface Writing clients and servers Concurrency with I/O multiplexing.
Network programming Nov 16, 2000 Topics Client-server model Sockets interface Echo client and server class24.ppt “The course that gives CMU its.
Carnegie Mellon Introduction to Computer Systems /18-243, spring th Lecture, Nov. 5 th Instructors: Roger Dannenberg and Greg Ganger.
Carnegie Mellon 1 Network Programming / : Introduction to Computer Systems 21 st Lecture, Nov. 8, 2012 Instructors: Dave O’Hallaron, Greg.
Network Programming Topics Sockets interface Writing clients and servers CS 105 “Tour of the Black Holes of Computing!”
Introduction A Simple Daytime Client A Simple Daytime Server
– 1 – , Spring 2006 Network Programming Introduction Jan. 25, 2006 Topics Programmer's view of the Internet Sockets interface Writing clients and.
Intro to Socket Programming CS 360. Page 2 CS 360, WSU Vancouver Two views: Server vs. Client Servers LISTEN for a connection and respond when one is.
Carnegie Mellon Introduction to Computer Systems /18-243, spring rd Lecture, Apr. 14 th Instructors: Gregory Kesden and Markus Püschel.
Networking Programming A Tiny Web Server 1. Outline Review of Web Server The Tiny Web Server Some Practical Issues Suggested Reading: –11.5~
1 Networking Programming (I). A Client-Server Transaction Client process Server process 1. Client sends request 2. Server handles request 3. Server sends.
1 Networking Programming. 2 Outline Connection & Socket Sockets Interface –Functions –Echo Client and Server Suggested Reading: –11.4.
Networking Alan L. Cox Some slides adapted from CMU slides.
Carnegie Mellon 1 Network Programming / : Introduction to Computer Systems 21 st Lecture, April 2, 2015 Instructors: Franz Franchetti, Seth.
– 1 – , Fall 2003 Network Programming Introduction Sept. 1, 2004 Topics Programmer's view of the Internet Sockets interface Writing clients and servers.
Sockets and Beginning Network Programming
Some slides adapted from CMU slides
Concurrent Servers December 7, 2000
Robust I/O package Chapter 11 practice problems
What is the Objective of Networking?
CS 1652 Jack Lange University of Pittsburgh
Concurrent Programming November 13, 2008
Instructors: Anthony Rowe, Seth Goldstein and Greg Kesden
Network Programming /18-243: Introduction to Computer Systems
CS 105 “Tour of the Black Holes of Computing!”
IE.
Network Programming April 11, 2008
Network Programming Jan 13, 2005
Internet Topics Client-server programming model Networks in general
Network programming Nov 27, 2001
Recitation 11 – 4/29/01 Outline Sockets Interface
Chapter 5 (part 1) TCP Client /Server Example By: Lim Meng Hui.
Web Services Topics Proxies Sockets interface
Network Programming Chapter 12
Networking Programming
Network Programming: Part II CSCI 380: Operating Systems Lecture #13
Networking Programming
Network Programming: Part II CSCI 380: Operating Systems
Network Programming November 3, 2008
Concurrent Programming November 13, 2008
Chapter 04. TCP Server/Client.
Socket Programming Neil Tang 09/08/2008
Example (UDP Client) // This program sends UDP packets to the given address #include #include #include #include.
Web Server Design Week 6 Old Dominion University
Web Server Design Week 7 Old Dominion University
Web Server Design Week 7 Old Dominion University
Presentation transcript:

Extending echo server HTTP Broken pipe error Feedback and evaluation 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

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

An Echo Client-Server Transaction 1. Client sends an input line Echo Client process Echo Server process 3. Client displays the text it receives 2. Server sends the same text as it receives

Review of the Sockets Interface Client Server socket socket connect bind open_listenfd open_clientfd listen Connection request accept Await connection request from next client rio_readlineb rio_writen close EOF rio_readlineb close

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

Echo Client: open_clientfd int open_clientfd(char *hostname, int port) { int clientfd; struct hostent *hp; 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; } This function opens a connection from the client to the server at hostname:port

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); }

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) ... (more)

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 listenfd; }

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); }

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 Client process Server Echo proxy process

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) Rio_writen(connfd, buf, n); } Close(forwardfd);

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

Different request and response (HTTP) Concurrency L7 Proxy Different request and response (HTTP) Concurrency Echo Client process Server Echo proxy process Web Browser process Web proxy process Web Server process

HTTP Request and Response Let’s use telnet to examine a simple HTTP request and response More details in Tuesday’s lecture

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

HTTP Request Request line: <method> <uri> <version> GET / HTTP/1.1 host: www.cmu.edu Request line: <method> <uri> <version> Request headers: <header name>: <header data> ‘\r\n’ to mark the end of the request

HTTP Response Response line: <version> <status code> <status msg> 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> . . . . . . Response headers: <header name>: <header data> ‘\r\n’ Response body: Web page

When reading or writing to a socket Broken Pipe Error When reading or writing to a socket If the socket has already been closed at the other end e.g. click “stop” on web browser SIGPIPE signal and EPIPE errno Don’t want to terminate the web server

Example of broken pipe with echo server Details Write to a broken pipe For the first write, return -1 and set EPIPE For subsequent writes, Send SIGPIPE signal, which terminates process If the signal is blocked or handled, return -1 and set EPIPE. Example of broken pipe with echo server

How to deal with broken pipe? Block SIGPIPE signal Ignore EPIPE error in Rio wrappers of csapp.c Example of how we handle broken pipe in echo server In server main(), we block SIGPIPE signal In csapp.c, we ignore EPIPE error in Rio wrappers In echo(), deal with cases when return value is -1

Feedback and Evaluation Thank you!