Building a http server, Computer Networking

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.

Posted Date: 2/21/2013 7:25:25 AM | Location : United States

Related Discussions:- Building a http server, Assignment Help, Ask Question on Building a http server, Get Answer, Expert's Help, Building a http server Discussions

Write discussion on Building a http server
Your posts are moderated
Related Questions
Uneven Load Distribution In the parallel computer, the problem is dividing into sub-problems and is assigned for computation to various processors. But sometimes the sub-probl

Discuss about LAN topologies LAN topologies:   Network topology is a physical schematic that demonstrates interconnection of the many users. There are four fundamental topolog

Repeater Repeater is  also named as active hub operates at physical  layer of OSI model. Repeater is an  electronic  device that simply regenerates the signal. Signals travell

What is the function of the OSI Session Layer? This layer gives the protocols and means for two devices on the network to communicate with each other by holding a session.  Thi

THICK ETHERNET WIRING:  It needs thick coax cable. AUI cable joins from NIC to transceiver. AUI cable take digital signal from NIC to transceiver. The transceiver creates anal

What is Redundancy? The method of including extra information in the transmission solely for the purpose of comparison. This technique is known as redundancy.

Configure IP Settings for the Linksys WRT300N The best way to understand the following settings is to think of the WRT300N as being same to a Cisco IOS-based router with two di

Internet  Mail Access Protocol Another  mail access  protocols  is internet  mail access  protocols  version 4 (  IMAP4). IMAP4 is  similar to POP3 but it  has more  feature

Explain the building blocks of Client/Server? The client side building block runs the client side of the application. The server side building block runs the server side of