$29
• Goal
In this project, we are going to develop a Web server in C/C++. Also, we will take the chance to learn a little bit more about how the Web browser and server work behind the scene.
• Lab Working Environment
You need a plain-text editor to create the source code. You may use vim/emacs/nano in Unix/Linux systems. Since C/C++ is a cross-platform language, you should be able to compile and run your code on any machine with C/C++ compiler and BSD socket library installed.
We recommend you develop and test your code in Ubuntu 16.04.3 LTS (Xenial Xerus). You may obtain a copy of Ubuntu 16.04.3 from its o cial website (http://releases.ubuntu.com/16.04/, 64-bit PC AMD64 desktop image) and install in VirtualBox (https://www.virtualbox.org) or other similar VM platforms. SEASnet linux servers are also accepted for testing. However, the OS you use must have a Web browser that ships with a graphical interface for testing. We do not support Windows workstations for Project 1 because of its di erent socket programming convention and behaviors. Use of macOS is allowed but not encouraged, since TAs may not provide support for OS-related issues other than Linux.
• Instructions
1. Read Chapter 2 of the textbook carefully. The textbook will help you understand how HTTP works. You can also use the socket programming materials covered by your TA to learn more on the C/C++ socket programming. Note that, you must program in C/C++ rather than in Java as the textbook shows.
2. Part A: Implement a \Web Server" that dumps HTTP request messages to the console. This is a good chance to observe how HTTP works. You should rst start your Web server, and then initiate a Web client. For example, you may open Mozilla Firefox and connect to your Web server. Your Web server should print out the HTTP request header it received. You should be able to explain what do the elds in the message mean by looking up in the textbook or RFC 1945. Do not provide extra debugging output in your submitted code.
3. Part B: Complete your \Web Server" by responding to client’s HTTP request. The \Web Server" should parse the HTTP request from the client, creates an HTTP response message consisting of the requested le preceded by header lines, then sends the response directly to the client.
1
UCLA CS 118 Project 1,
Your server should correctly transmit le content as binary data. Whatever data received by an HTTP client should be identical to the data requested, which can be checked by the diff program. If the requested le does not exist, your server should display an HTML page showing 404 not found error.
Your server should support several common le formats, so that a standard Web browser can display such les directly, instead of prompting to save to local disk if the le format is not supported. The minimum supported le types must include the seven types listed below:
plain text les encoded in UTF-8: *.html, *.htm, and *.txt
static image les: *.jpg, *.jpeg, and *.png
animated image les: *.gif
A Web client may request a le with or without le extension. File names are handled in a case-insensitive fashion (i.e. ABC.jpg and for abc.JPG are referring to the same le), therefore an HTTP request for ABC.jpg should get a valid response if abc.JPG exists on the requested path on the server. Your server code also needs to handle the case where le name contains space. For example, a le named new image.jpg on the server should be served correctly if it is requested. Your server does not need to handle requests for les in any subdirectories. All les are supposed to be accessed in the same directory as the actual server program.
4. Pay attention to the following issues when you are implementing and testing the project.
If you run the server and a Web browser on the same machine, you may use localhost or 127.0.0.1 as the name of the machine. Instead of using port 80 or 8080 for the listening socket, you should pick your own to avoid con icts. It is suggested not to use port numbers 0 { 1024 (these are reserved ports).
After you are done with both parts, you need to test your server. You can rst put an HTML le in the directory of your server program. Then, you should connect to the server from a browser using the URL http://<machinename>:<port>/<filename> and see if it works. For your server in Part A, you should be able to see HTTP requests in the console of your server machine. For your server in Part B, your browser should be able to show the content of the requested le (or displaying image).
• Grading Criteria
Your code will be rst checked by a software plagiarism detecting tool. If we nd any plagiarism, you will not get any credit and we are obliged to report the case to the Dean of Student. Your code will be graded based on several testing rubrics. We list the main grading criteria below; more details will be announced via CCLE.
The server program compiles and runs normally.
The server can print out the correct HTTP request messages to the console. The server program transmits a small binary le (up to 512 bytes) correctly. The server program transmits a large binary le (up to 100 MB) correctly.
The server program serves an HTML le correctly and it can show in the browser.
2
UCLA CS 118 Project 1,
The server program serves an image le correctly and it can show in the browser.
The server program serves a le which le name contains space correctly in the browser.
• Project Submission
Project due date is 11:59 p.m. on Friday, April 26th on CCLE. Late submission is allowed by Sunday, April 28th (10% deduction on Saturday, 20% deduction on Sunday). Put all your les into a directory, compress the directory and generate a UID.tar.gz where UID is your UCLA ID. Only one member of your team is required to submit your project to CCLE. Your submission should include the following les:
Your source codes (e.g. webserver.c). The code of the server can be more than one le. A Make le. The TAs will only type make to compile your code.
Your report in PDF format only (report.pdf).
A README le which will contain student names and student IDs.
Your report should not exceed 6 pages. In your report:
1. Give a high-level description of your server’s design.
2. What di culties did you face and how did you solve them?
3. Include a brief manual in the report to explain how to compile and run your source code (if TAs cannot compile and run your source code by reading your manual, the project is considered not to be nished).
4. Include and brie y explain some sample outputs of your client-server (e.g. in Part A you should be able to see an HTTP request). You do not have to write a lot of details about the code, but just adequately comment your source code. The cover page of the report should include the name of the course and project, your partner’s name, and student ID.
3