Log in

Simple Web Server

[edit]

Introduction

A web server is basically a program which listen on a port (80) and send the content of HTML pages to the client which has requested it.

[edit]

HTTP Protocol

The HTTP protocol is quite simple if you consider simple requests. The most common requests are:

Both methods are used to request HTML pages. They are different in the way of passing arguments (if any). For our purpose, we only manage the GET method and do not handle parameters. The format of a GET request is as follows:

GET URI PROTOCOL

The URI can be an absolute URL (e.g.: http://tuxigloo.org/index.html) or a relative URL (e.g. /index.html).

The protocol is "HTTP/" followed by the version of HTTP. The version 1.0 is usually used. This field is optional.

So for example, a GET request can be as follows:

GET http://tuxigloo.org/index.html HTTP/1.0

The server then replies by sending a header plus the content of the requested file. The header is something like:

HTTP/1.0 200 OK
Content-Length: 234
Content-Type: text/html

The content-length is the size of the requested file. The content-type is the type of the requested file. It is determined either by the file extension or by its magic cookie (first two bytes of the file).

[edit]

Design

The web server has to manage several connections at the same time. So in the implementation, you can use the fork or thread function to handle them. You will understand more by looking at the source. You can download the full archive here

Retrieved from "http://www.tuxigloo.org/wiki/Simple_Web_Server"

This page has been accessed 813 times. This page was last modified 07:14, 23 June 2006.