HTTP server in Linux

Source: Internet
Author: User

It is not difficult to implement a simple web server in Linux. A simple HTTP server is just an advanced file server that constantly receives HTTP requests sent by clients (browsers), parses requests, Processes requests, and then sends data back like a client. In most cases, (get and POST commands), all files (HTML documents, images, JavaScript scripts, etc.) that the service requests are sent back to the client ).

The following is a simple HTTP server demo. Although it only processes get requests and sends a single file, it basically shows the Web Server framework. My example tries to streamline the functions and structure so that the basic structure of an HTTP server is clear at a glance.

# Include <sys/socket. h> # include <errno. h> # include <netinet/in. h> # include <string. h> # include <stdio. h> # define buf_len 1028 # define server_port 8080 // defined HTML page, in actual cases, the web server basically reads the HTML file const static char http_error_hdr [] = "HTTP/1.1 404 Not found \ r \ ncontent-type: text/html \ r \ n "; const static char http_html_hdr [] =" HTTP/1.1 200 OK \ r \ ncontent-type: text/html \ r \ n "; const static char http_index _ HTML [] = "<HTML> 

less than 80 codes can be used to implement an ultra-simple HTTP server.

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.