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.

Purpose

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 :

GET HTTP/1.0

{ }*

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

Server:

Content-type:

{ }*

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

Server:

Content-type:

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 https://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

What is the virtual path, Along any transmission path from a given source t...

Along any transmission path from a given source to a given destination, a group of virtual circuits can be grouped together into what is known as path.

Explain the concept of token passing, Token Passing S...

Token Passing Station is able to send only when it receives a special frame called a token Token circulates around the ring If station wishes to sen

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 203.220.72.0/24. The hotel provides a number of eatery, office, accommodation and conference like services. This

Barters, What is a OSI layer 2 device called a "barter"?

What is a OSI layer 2 device called a "barter"?

The concept of universal service, The major problems with multiple networks...

The major problems with multiple networks are as given: A computer attached to a given server can only interact with other computers attached to the similar network.

Parallel programming environment characteristics, Parallel Programming Envi...

Parallel Programming Environment Characteristics  The parallel programming environment consists of an debugger, a editor,  performance evaluator and programme visualizer for i

What are the hardware requirement for an intranet, Hardware requirement for...

Hardware requirement for an intranet To setup a WAN, one would need to have some type of communication between different sites. National ISDN, Very Small Aperture Terminal (VSA

Name the presentation layer standards, A.) JPEG and PICT B.) MPEG and MI...

A.) JPEG and PICT B.) MPEG and MIDI C.) ASCII and EBCDIC For example, the Presentation layer would be liable for changing from EDCDIC to ASCII. Data compression, decompres

Explain data communications, The distance over which data moves within a co...

The distance over which data moves within a computer may differ from a few thousandths of an inch, as is the case within a one IC chip, to as much as lot of feet along the backplan

Write Your Message!

Captcha
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