COM SCI 118 Spring 2021 Computer Network Fundamentals: 1 Goal
COM SCI 118 Spring 2021 Computer Network Fundamentals: 1 Goal
1 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.
3 Instructions
1. Read the HTTP sections in Chapter 2 of the textbook carefully. The textbook will help
you understand how HTTP works. For details of HTTP, you can refer to RFC 1945 (https:
//tools.ietf.org/html/rfc1945). You should go over carefully on the socket programming
slides posted and discussed by the TAs. Note that, you must program in C/C++ rather than
in Java as the textbook shows.
2. Implement a “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 file preceded by header lines, then sends the response directly to the client. In
order to test it, you should first start your Web server, and then initiate a Web client. For
example, you may open Mozilla Firefox and connect to your Web server.
1
UCLA CS 118 Project 1, Spring 2021
3. Your server should support several common file formats, so that a standard Web browser can
display such files directly, instead of prompting to save to local disk. The minimum supported
file types must include the four types listed below:
Your server should also correctly transmit file content as binary data if the filename does not
contain any file extension. Whatever data received by an HTTP client should be identical to
the data requested, which can be checked by the diff program. (Hint: you can set MIME
type of the HTTP response as application/octet-stream for binary file requests.)
Your server does NOT need to handle the following scenarios:
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 conflicts. It is suggested not to use port numbers
0 – 1024 (these are reserved ports).
After you are done with implementing the web server, you need to test it. You can first
put an HTML file in the directory of your server program. Then, you should connect to
the server from a browser using the URL http://<machinename>:<port>/<filename> (e.g.
http://localhost:5000/test.html) and see if it works. Your browser should be able to
show the content of the requested file (or displaying image).
5. Useful tips:
• It would be helpful for debugging if you print out the HTTP request header that the
server received.
• When constructing the HTTP header response, you only need to implement required
header fields. For example, http version, status code, content-type, etc.
• If the client does not recognize the body data, please check whether you put a blank line
after the last line of your HTTP header, i.e. \r\n\r\n .
• If the browser can successfully receive the response of a text file but fails to display the
content. This means that your server probably only sends null bytes to the browser. You
can verify this by changing the content type to application/octet-stream to download this
file and use hexdump to examine the file.
6. Bonus points:You will get 15% bonus points if your server can handle the following cases
• The client requests a file with a file name containing white spaces (e.g. ucla icon.jpg).
• The client requests a file with a file name containing % signs (e.g. ucla%icon.jpg).
2
UCLA CS 118 Project 1, Spring 2021
4 Grading Criteria
Your code will be first checked by a software plagiarism detecting tool. If we find 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 transmits a binary file (up to 1 MB) correctly. We will test binary file
transmission by requesting a filename with no extension. You can test this function with the
following commands.
• The server program serves a plain text file correctly and it can show in the browser.
• The server program serves an image file correctly and it can show in the browser.
5 Project Submission
Project due date is 11:59 p.m. on Friday, April 23th on CCLE. Late submission is allowed by
Sunday, April 25th (20% deduction on Saturday, 40% deduction on Sunday). Put all your files into
a directory, compress the directory and generate a UID.tar.gz where UID is your UCLA ID. Your
submission should include the following files:
• Your source codes (e.g. webserver.c). The code of the server can be more than one file.
• A Makefile. The TAs will only type make to compile your code.