130 likes | 248 Views
Programming Project #3 Simple Web Server. CS-4513 D-Term 2007
E N D
Programming Project #3Simple Web Server CS-4513D-Term 2007 (Slides include materials from Operating System Concepts, 7th ed., by Silbershatz, Galvin, & Gagne, Modern Operating Systems, 2nd ed., by Tanenbaum, and Distributed Systems: Principles & Paradigms, 2nd ed. By Tanenbaum and Van Steen) Programming Project #3
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 #3
Operation % webserver port# <directory> [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 #3
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 #3
Two HTTP “rules” • Prefix directory name to all files:– • If user asks your server for • http://ccc4.wpi.edu:4242/admissions.html • … it supplies • <directory>/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 #3
Mini-primer on HTTP • GET request looks like:– GET /index-t.html HTTP/1.0Connection: Keep-AliveUser-Agent: Mozilla/4.7 [en] (X11; U; SunOS 5.7 sun4u)Host: ccc1.wpi.edu:4242Accept: image/gif, image/x-xbitmap, image/jpeg, image/png, */*Accept-Encoding: gzipAccept-Language: enAccept-Charset: iso-8859-1,*,utf-8 • You need only to • Interpret “GET” commands • HTTP/1.0 • Recognize end of header – CR/LF (i.e., \r\n) Programming Project #3
Responses • HTTP/1.0 200 OK\r\n\r\n • Followed by the page itself or • HTTP/1.0 404 Not Found\r\n\r\n • Many HTTP references on the web. • For tutorial, see • http://www.jmarshall.com/easy/http/ Programming Project #3
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 #3
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 #3
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 #3
Project Submission • Due Friday, April 27, 2007 • Via myWPI • Zip files together to <yourID>-Project3.zip • Individual project • However, you may discuss HTTP protocol with each other • Share discussions by e-mail with class Programming Project #3
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 #3
Extra Credit • Modify webserver to support multiple, concurrent, persistent web connections at one time — 50% • Demonstrate that it does Programming Project #3