Linux serverlinux web serverNETWORK ADMINISTRATIONS

Project 1: Web Server Implementation using BSD Sockets

Download Link:
https://codesy.sellfy.store/p/jcgmwd

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

You should test and develop your code in Ubuntu 16.04.3 LTS (Xenial Xerus), as your submis-sion will be tested in this environment. You can 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 platform. We also provide pre-installed virtual machine images on our server (username/password: cs118/cs118):

For VirtualBox: http://metro.cs.ucla.edu/cs118/CS118_OVF.rar

For VMware: http://metro.cs.ucla.edu/cs118/CS118.rar

It is recommended to work your project in Linux/Unix/macOS systems. It is also highly recommended that testing your code in the speci ed environment. Windows workstations are NOT recommended, because they have their own idiosyncracies which may be too much for this simple project. Also, TAs will not be able to help you on any of these platforms.

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

You must program in C/C++ (not Java). To help you get familiar with socket program-ming, we provide a demo client-server code at https://wing1.cs.ucla.edu/gitlab/zyuan/ cs118-project1-demo (public repo, no need to register for an account). This code is also included in the VM we provide above.

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

1
CS 118 Project 1

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

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.

If the requested le does not exist, your server should be able to display an HTML page showing 404 not found error. Your server does not need to handle requests for les in any subdirectories. All les are supposed to be accessed in the same level as the actual server program. However, your server does need to handle the case where le name contains space.

Your server should at least support HTML les (i.e. *.html and *.htm). It should also support for JPEG and GIF images (i.e. *.jpg, *.jpeg, and *.gif). All the le extensions are case insensitive.

4. Pay attention to the following issues when you are implementing and testing the project.

If you are running the browser and server 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 or 6789 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).

source

by Codinch

linux web server