Programming Project #3CS-4513, D-Term Programming Project #3 Simple Web Server CS-4513 D-Term 2007 (Slides include materials from Operating System Concepts, 7 th ed., by Silbershatz, Galvin, & Gagne, Modern Operating Systems, 2 nd ed., by Tanenbaum, and Distributed Systems: Principles & Paradigms, 2 nd ed. By Tanenbaum and Van Steen)
Programming Project #3CS-4513, D-Term Goal —Simple Multi-threaded Web Server Capable of serving up real web pages Interpreting (a subset of) HTTP protocol Run on CCC machines Also, a web client for debugging purposes
Programming Project #3CS-4513, D-Term Operation % webserver port# [verbose | basic] Create socket, bind to your port# Listen on socket for connection requests In a loop Wait for and accept() connection Spawn a thread to handle connection Repeat …
Programming Project #3CS-4513, D-Term Operation (continued) … Spawned thread must Read client’s request from socket Find file, deliver to client via the socket –(or respond with error indication) Close connection and terminate
Programming Project #3CS-4513, D-Term Two HTTP “rules” Prefix directory name to all files:– –If user asks your server for –… it supplies /admissions.html (WPI’s web pages are on /www/docs ) If name ends in “/” or resolves to directory Append “ index.html ” to path name Note: it does not hurt to have extra “/” characters
Programming Project #3CS-4513, D-Term Mini-primer on HTTP GET request looks like:– GET /index-t.html HTTP/1.0 Connection: Keep-Alive User-Agent: Mozilla/4.7 [en] (X11; U; SunOS 5.7 sun4u) Host: ccc1.wpi.edu:4242 Accept: image/gif, image/x-xbitmap, image/jpeg, image/png, */* Accept-Encoding: gzip Accept-Language: en Accept-Charset: iso ,*,utf-8 You need only to –Interpret “ GET ” commands –HTTP/1.0 –Recognize end of header – CR/LF (i.e., \r\n )
Programming Project #3CS-4513, D-Term Responses HTTP/ OK\r\n\r\n Followed by the page itself or HTTP/ Not Found\r\n\r\n Many HTTP references on the web. –For tutorial, see
Programming Project #3CS-4513, D-Term Testing webclient host port# web-page Send a simple HTTP request to {host, port} Prints out the response verbose & basic arguments on webserver Prints out detailed or summary requests and responses to standard out
Programming Project #3CS-4513, D-Term Multi-threading You must demonstrate that your server correctly handles concurrent requests in a multi-threaded way –E.g., adapt webclient to take multiple arguments, spawn separate threads, and Show from debug logs that requests are interleaved
Programming Project #3CS-4513, D-Term Extra-credit Modify your server to support persistent connections I.e., either HTTP v1.1 or Connection: Keep-Alive At end of request, Do not close connection Do not terminate thread Terminate After timeout Connection: close
Programming Project #3CS-4513, D-Term Project Submission Due Friday, April 27, 2007 Via myWPI Zip files together to -Project3.zip Individual project However, you may discuss HTTP protocol with each other Share discussions by with class
Programming Project #3CS-4513, D-Term Grading Submission via myWPI — 5% Successful make on CCC machines — 5% No warnings Clear, cogent, write-up — 15% Successful operation of webserver on CCC — 25% Fetch WPI web pages with standard browser Successful operation of webclient — 25% Fetch WPI web pages from standard server Successfully demonstrate that server supports more than two concurrent HTTP requests at once — 25%
Programming Project #3CS-4513, D-Term Extra Credit Modify webserver to support multiple, concurrent, persistent web connections at one time — 50% Demonstrate that it does