Project 1: Web Server Implementation using BSD Sockets Solution

$35.00 $29.05

You'll get a: . zip file solution, download link after Payment

Description

  • 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. No high-level network-layer abstractions (like httplib, Boost.Asio or similar) are allowed in this project. You are allowed to use some high-level abstractions, including C++11 extensions, for parts that are not directly related to networking, such as string parsing.

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. Note 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 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.

    1. 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 le preceded by header lines, then sends the response directly to the client. In order to test it, 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.

1

UCLA CS 118 Project 1, Spring 2020

  1. 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. The minimum supported le types must include the four types listed below:

plain text les encoded in UTF-8: *.html and *.txt

static image les: *.jpg and *.png

Your server should also correctly transmit le content as binary data if the lename does not contain any le 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 le requests.)

Your server does NOT need to handle the following scenarios:

The client requests for les in any subdirectories. The client request a le that does not exist.

The client request a le named with special characters other than alphabets and period.

  1. 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 implementing the web server, you need to test it. 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> (e.g. http://localhost:5000/test.html) and see if it works. Your browser should be able to show the content of the requested le (or displaying image).

  1. 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 just need to add the header elds required. 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. nrnnnrnn .

If the browser can successfully receive the response of a text le 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 le and use hexdump to examine the le.

  • 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.

2

UCLA CS 118 Project 1, Spring 2020

The server program compiles and runs normally.

The server program transmits a binary le (up to 1 MB) correctly. We will test binary le transmission by requesting a lename with no extension. You can test this function with the following commands.

$ cat /dev/urandom | head -c 1000000 > binaryfile # generate a 1MB file

$ curl -o downloadfile <machinename>:<port>/binaryfile # request the file

    • diff downloadfile binaryfile # check if the downloaded file is intact

The server program serves a plain text le correctly and it can show in the browser. The server program serves an image le correctly and it can show in the browser.

  • Project Submission

Project due date is 11:59 p.m. on Friday, April 24th on CCLE. Late submission is allowed by Sunday, April 26th (20% deduction on Saturday, 40% 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. 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.

A README le which will contain following information { Your name, email, and UCLA ID

{ The high level design of your server (one paragraph)

{ The problems you ran into and how you solved the problems (up to three paragraphs)

{ List of any additional libraries used Acknowledgement of any online tutorials or code example (except class website) you have been using.

3