CS 475 ­ Networks Fall 2011 ­ Programming Project 6

advertisement
CS 475 ­ Networks
Fall 2011 ­ Programming Project 6
40 points
Out: November 22, 2011
Due: December 9, 2011 (Friday of finals week) – NO LATE WORK ACCEPTED
Note that this project is worth double of the other projects.
Assignment
Write a HTTP/1.0 compliant (non­persistent connections) web server. The server should serve web pages from a www_cs475 subdirectory of your home directory on csserver. When the server is first started it should display the port number the server is listening on (i.e., use dynamic port assignment). The server should be written so that the default directory name can be changed easily.
You should be able to browse to pages being served by your server using a URL of: http://csserver.evansville.edu:<port#>/ (where <port#> is the port number displayed by the server). This base URL should cause the index.html page from your www_cs475
directory to be served. URLs for directories should serve the index.html page from the named directory.
Direct links to web pages should work, for example, http://csserver.evansville.edu:<port#>/mypics/fluffy.jpg should serve file fluffy.jpg from the mypics subdirectory of www_cs475. Relative URLs to pages within your website from pages within your website should work, too. (But be careful not to allow access to files above the www_cs475 directory).
The server must be able to serve HTML text files. In order to earn maximum credit, the server also must be able to serve image files as noted below. You may assume that the extension of a file is correct relative to its content. (E.g. a file with .gif extension will be a GIF image file.) Research how to convert an image file into MIME format. Use Content­Type and other message headers as appropriate. Helpful hints:
1. Since non­persistent connections are being used, you do NOT need to handle multiple clients simultaneously. The server should close the connection when it has finished sending its response.
2. Commands from the browser may be multiple lines long, but are required to end with a blank line. The server should do multiple (if necessary) read()s until the string “\r\n\r\n” (a double carriage return and newline) appears or end­of­file (read() returns 0) is reached.
3. Most browsers will issue a GET command for a favicon.ico file in order to display a small thumbnail image in the URL bar or in the brower tab. The thumbnail image should be an image that “represents” your website. Your server should either return this file (if it exists) or just close the socket (i.e., it should not generate a NOT FOUND error). You can create an ico image using most image editing programs.
11/22/2011
Page 1 of 2
D. Hwang
For full credit, your program should use a modular or object­oriented design. (I.e., the entire program should not be in main()!) Grading
Grades for this project will be awarded based on the following criteria:
70% correctly serving HTML files
10%
correctly serving image files
10% readability (including comments)
10%
elegance of design What to submit
Create a makefile that will make your server, and create a tarfile or zipfile containing it and the program source files.
● Email your tarfile/zipfile to the instructor, hwang@evansville.edu
●
11/22/2011
Page 2 of 2
D. Hwang
Download