Tiny HTTPd Open source Web server building process and brief analysis

Source: Internet
Author: User

Open source Web server, Tiny HTTPd, pure C writing, Jdavidb. The server is small, lightweight, simple structure, the principle of building a Web server is very clear, it is very helpful for learning.


Test environment: Ubuntu 14.04.2

Because the server is not developed by default for Linux, it requires simple modifications to run on Linux.

1, modify the makefile file, will gcc-w-wall-lsocket-lpthread-o httpd httpd.c

Modified to: Gcc-w-wall-o httpd httpd.c-lpthread. (deleting-lsocket,linux does not require-lsocket.) Put-lphtread in the end, find the results on the internet is-lphtread can not be placed in front of-O, the specific reason is unknown)

In fact, in the source code HTTPD.C, introduced in the Linux system compile, need to modify the place, (or to carefully read the source code).

2, Htdocs folder, there are two CGI script files for the response of this server, written in Perl language, because the machine default Perl installation location is different, so you need to change to the native Perl address.

After two changes, make, the server can be successfully built up.


The server has three ways of interacting:

1, enter the Ip:port address directly, the server opens the Index.html file under the Htdocs folder, enter a color in the revenue box, such as red or 0 0 0, index.html call color.cgi script to display the color.

2, direct access to the Htdocs folder under the script, such as ip:port/color.cgi, the default is blue, or another script file index.html/check.cgi.

3, can directly access the Htdocs folder under the file, such as Ip:port/readme, will print the file.


Summarize:

1, Name.sin_port = htons (*port)

If *port is 0, the system randomly assigns the port number

2, name.sin_addr.s_addr = Htonl (Inaddr_any);

Inaddr_any: This represents any IP address, if the server has more than one network card, multiple IP addresses, through a number of IP addresses + ports can access the server

3, newline is linefeed: line break LF \ n to the next line of the forefront

Carriage return return CR \ R Return to the beginning of the current line

4. STRCASECMP ignores case comparison strings are equal, Isspace determines whether a character is a null character, or NULL returns True


Tiny HTTPd Open source Web server building process and brief analysis

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.