Building a http server, Computer Networking

Assignment Help:

IMPORTANT: The web server should be able to serve HTTP files only. You will not need to implement the directory listing and CGI-bin.


The objective is to implement a HTTP server that will allow a HTTP client (a web browser like FireFox or Internet Explorer ) to connect to it and download files.

HTTP Protocol Overview

A HTTP client issues a 'GET' request to a server in order to retrieve a file. The general syntax of such a request is given below :


{ }*

where :

  • stands for a whitespace character and,
  • stands for a carraige return-linefeed pair. i.e. a carriage return (ascii character 13) followed by a linefeed (ascii character 10).
  • is also represented as "\n\n".
  • gives us the name of the file requested by the client. This could be just a backslash ( / ) if the client is requesting the default file on the server.
  • { }* contains useful ( but not critical ) information sent by a client. These can be ignored for this project. Note that this part can be composed of several lines each seperated by a .
  • * - kleene star // regular expressions

Finally, observe that the client ends the request with two carriage return linefeed character pair:

The function of a HTTP server is to parse the above request from a client, identify the file being requested and send the file across to the client. However, before sending the actual document, the HTTP server must send a response header to the client. The following shows a typical response from a HTTP server when the requested file is found on the server:

HTTP/1.0 200 Document follows



{ }*

where :

  • identifies the manufacturer/version of the server. For this project, I will tell this in an email very soon but it should not affect the rest of the coding.
  • indicates to the client, the type of document being sent. This should be "text/html" for an html document, "image/gif" for a gif file, "text/plain" for plain text, etc.
  • {}* as before, contains some additional useful header information for the client to use. These may be ignored for this project.
  • is the actual document requested. Observe that this is separated from the response headers be two carraige return - linefeed pairs.

If the requested file cannot be found on the server, the server must send a response header indicating the error. The following shows a typical response:

HTTP/1.0 404 File Not Found



where :

  • indicates the type of document (i.e. error message in this case) being sent. Since you are going to send a plain text message, this should be set to text/plain.
  • is a human readable description of the error in plain text/html format indicating the error (e.g. Could not find the specified URL. The server returned an error).

Procedure and Algorithm Details

Stage 0:

The source of an example time server program called daytime-server are provided:

gunzip lab5-src.tar.gz

tar -xvf lab5-src.tar

Then build the server by typing make. Run the server by typing daytime-server without arguments to get information about how to use the server. Run the server and read the sources to see how it is implemented. Some of the functionality of the HTTP server that you will implement is already available in this server.

Stage 1:

Basic Server

You will implement an iterative HTTP server that implements the following basic algorithm:

  • Open Passive Socket.
  • Do Forever
  • Accept new TCP connection
  • Read request from TCP connection and parse it.
  • Frame the appropriate response header depending on whether the URL requested is found on the server or not.
  • Write the response header to TCP connection.
  • Write requested document (if found) to TCP connection.
  • Close TCP connection

The server that you will implement at this stage will not be concurrent, i.e., it will not serve more than one client at a time (it queues the remaining requests while processing each request). You can base your implementation on the example server given in [1] . The server should work as specified in the overview above. Make a copy of the daytime server and name it "myhttpd.cpp". Add the rules to the Makefile to build it.

Adding Concurrency

You will also add concurrency to the server. You will implement three concurrency modes. The concurrency mode will be passed as argument. The concurrency modes you will implement are the following:

-f :  Create a new process for each request

In this mode your HTTP server will fork a child process when a request arrives. The child process will process this request while the parent process will wait for another incoming request. You will also have to prevent the accumulation of inactive zombie processes. You can base your implementation on the server given in [3]

-t : Create a new thread for each request

In this mode your HTTP server will create a new thread to process each request that arrives. The thread will go away when the request is completed.

-p:  Pool of threads

In this mode your server will put first the master socket in listen mode and then it will create a pool of 5 threads where each thread will execute a procedure that has a while loop running forever which calls accept() and dispatches the request. The idea is to have an iterative server running in each thread. Having multiple threads calling accept() at the same time will work but it creates some overhead under Solaris (See [4]). To avoid having multiple threads calling accept() at the same time, use a MUTEX lock around the accept() call.

The format of the command should be:  

myhttpd [-f|-t|-p] []


If no flags are passed the server will be an iterative server like in the Basic Server section. If is not passed, you will choose your own default port number. Make sure it is larger than 1024 and less than 65536.

URL to File Mapping

In Apache and other web  servers, the mapping from URL documents to directories in the file system is done through a configuration file. In your project you will do this mapping programatically in the following way:

If document is icons/document in the URL, then it will serve the document from http-root-dir/icons/document.

If the document is cgi-bin/script, then your server will execute the scrip in http-root-dir/cgi-bin.

Otherwise, the document requested will be served from http-root-dir/htdocs. The document could be a subdirectory or a file in a subdirectory in htdocs.

IMPORTANT: A URL for your server should not contain http-root-dir or htdocs in it.

IMPORTANT: Make sure that a user should not be able to request/browse files above the htdocs/ cgi-bin/ or icons/ directories. You can use the "realpath" function to translate paths with ".." and other relative paths to absolute paths.

IMPORTANT: The default page when requesting http://host:port should be the index.html in htdocs.

Make sure that your server uses the http-root-dir and it loads by default the index.html from this directory. Test the simple, complex test.

Write a short README file that includes:

        a) Features in the handout that you have implemented av

        b) Features in the handout that you have not implemented

        c) Extra features

Write your program in a directory called lab5-src. Make sure that your server can be built by typing "make".

IMPORTANT: Do not include the http-root-dir in your submitted files.

Related Discussions:- Building a http server

Identify three udp characteristics, UPD is a layer 4 Transport protocol. It...

UPD is a layer 4 Transport protocol. It is connection-less due to it does establish a connection thus the 3 step handshake is not needed, it does NOT execute any flow control or ac

Tcp segment structure - transport layer, TCP Segment Structure Figure ...

TCP Segment Structure Figure shows the format of the TCP segment. The  header consists  of a 20 bytes  fixed  part  plus a variable size  options fields. The description  o

Differentiate between adsl and dsl, ENTERPRISE NETWORKING 1. Explain th...

ENTERPRISE NETWORKING 1. Explain that what is a cable? Classify different types of cables. 2. Elaborate switch? Write down the functionalities of switch. 3. Describe rout

Layer on which layer does l2f, Write the layer on which layer does L2F, PPT...

Write the layer on which layer does L2F, PPTP and L2TP operate?

Subnet masking and designing small networks, The hotel has a class C public...

The hotel has a class C public address space. The network number is The hotel provides a number of eatery, office, accommodation and conference like services. This

Hardware difficulty, Hardware difficulty It refers to the price of hard...

Hardware difficulty It refers to the price of hardware logic like connectors, wires, switches, arbiter etc. that are required for execution of interconnection network.

Command to copy the ios image to a tftp server, What is the command to copy...

What is the command to copy the IOS image to a TFTP server? Ans) Copy flash tftp

Describe ethernet, Describe Ethernet. Ethernet is one of the well-liked...

Describe Ethernet. Ethernet is one of the well-liked networking technologies used these days. It was developed during the early 1970s and is based on specifications as stated i

Give example of the physical layer, FDDI, Token Ring and Ethernet are all p...

FDDI, Token Ring and Ethernet are all physical layer framing standards.

Write Your Message!

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd