Mongoose Source Analysis: External Web server

Source: Internet
Author: User

Turn http://www.cnblogs.com/skynet/archive/2010/07/24/1784110.html

There's a lot of mongoose in this blogger.

Introduction

Before delving into the mongoose source, we should know what the Web server is. What services does it offer? How to provide service? What protocol is used? How do clients uniquely identify a Web server's resources? Let's put aside mongoose to introduce the continuity of a Web service.

Web server: Usually refers to a computer program (What is a Web server?). ), provide services such as Web pages on the World Wide Web ( What services are available?). ), using hypertext Transfer Protocol (HTTP) ( What protocol is used?). ). Of course, the Web server can also refer to the computer running this program or virtual machine, we are talking about the Web server refers to the program.

The main contents of this article are as follows:

    • 1. Web server
    • 2. How the Web server provides services
    • 3. Protocols used by web servers
    • 4. How clients uniquely identify a Web server's resources
    • 5, the current more popular web server
1. Web server

The main function of the Web server is to send the Web page to clients. This means that the HTML document and other content contained in the document, such as images, style sheets, javascripts, are transferred. The client is typically a Web browser or web crawler that initiates a request for a specified resource using HTTP, the Web server responds to the request with the specified content, or returns an error message when the specified request cannot be made. The requested resource is typically an actual file on the secondary storage of the Web server, but this is not required, depending on the implementation of the Web server.

While the main function of a Web server is to provide content, a complete HTTP implementation also includes receiving content from the client. This feature is used to submit Web forms, including uploading files.

Many Web servers also support server-side scripting, such as the Apache HTTP server and PHP. This means that the behavior of the Web server can be written as a script separated into scattered files, while the actual server software remains intact. Typically, this feature is used to create an HTML document relative to returning a fixed document. This involves dynamic and static content, respectively. The former primarily retrieves and/or modifies information in the database, whereas the latter is usually faster and easier to cache.

Web servers are not always used on the World Wide Web, or can be embedded in printers, routers, webcams, and local networks, where the Web server can be used for monitoring parts of the system or for managing parts of the device.

2. How the Web server provides services

Did you ever think about how it was displayed to your browser when you saw my blog in the browser? Although this process largely depends on the Web server, they still have commonalities. Typically, when a user browses a Web site by clicking on a hyperlink or entering a URL in the address bar of the browser. But how does the same site appear on different computers on the network at the same time?

Take my blog's homepage as an example, when you enter http://home.cnblogs.com/skynet/in the address bar of the browser, through an Internet connection, by converting the domain name to an IP address, and then targeting the blog Park server, Your browser Initializes a connection to the blog Park Web server. The Web server stores all of the resources on my blog, such as every article I write, the pictures I use in my articles, the CSS, scripts, and so on in my blog templates.

Once the connection is established, the browser uses HTTP to request data from the Web server, and the server transmits the data to your browser. The browser then transforms and formats the data to display in your browser. Similarly, a Web server can simultaneously take files to multiple clients, allowing multiple clients to browse the same page at the same time.

Figure 1, Web client interaction with server side

Of course, I describe here the relatively simple, more detailed steps please refer to:

    • What really happens if you navigate to a URL
    • What happens when you enter a URL?
3. Protocols used by web servers

Believe that through the above introduction, you already know that the Web server and the client is through HTTP to interact. About HTPP, I've written about this before: the HTTP protocol and its post and get operation differences & how to use post, get in C #, I highly confident recommend you to read the following article, in more detail about the HTTP and its interaction with the client process, I'm not going to be too tired here.

4. How clients uniquely identify a Web server's resources

URI, that's right. The Uniform Resource Locator (Uniform Resource Identifiers), which uniquely identifies a Web page on the Internet. But you may hear more of the URL, which is the abbreviation for Uniform Resource location, translated as "Uniform Resource Locator." In layman's words, URLs are strings used on the Internet to describe information resources, mainly used in various WWW client programs and server programs. URLs can be used in a unified format to describe various information resources, including files, server addresses and directories.

The format of the URL, the format of the URL consists of the following three parts:

    • The first part is the protocol (or service mode)
    • The second part is the host IP address (and sometimes the port number) where the resource is stored
    • The third part is the specific address of the host resource, such as directory and file name.

The first and second sections are separated by a "://" Symbol, and the second and third sections are separated by a "/" symbol. The first part and the second part are indispensable, and the third part can be omitted sometimes. Actually about://is not necessary, but the World Wide Web was originally designed, please google or Baidu "the father of the World Wide Web said http://In the two slash in fact superfluous." The full URL format is as follows:

Scheme://username:[email protected]:p Ort/path?query_string#anchor

Scheme is what we call the Protocol section above, the Web server usually uses HTTP and HTTPS, but it can also be gopher, WAIS, FTP, mailto.

Username:[email protected]:p ORT is the second part of what we said above, generally we do not have to enter the user name and password, as well as the port (the HTTP protocol port number is 80, which is usually used by default), and just enter the domain name Orip address.

Path?query_string#anchor is the third part of what we said above, path specifies the resource on the server (note: Like this archive/2010/05/18/1738301.html, it is not necessarily the absolute path on the Web server, Instead, it is the path after the URL rewrite, but anyway, it uniquely identifies the path to the resource on the server, and later query_string contains data that is passed to the Web application (such as CGI). The query string is in the form of a key/value pair, and each key-value pair is separated by &, such as userid=skynet&password=123456; last when using HTTP, #anchor表示web页面的某一个部分.

Take the HTTP protocol and its post vs. get operation differences & how to use post, get, and so on in C # its URL is: http://www.cnblogs.com/skynet/archive/2010/05/18/1738301.html.

The above mentioned URI and URL, there are certain people do not know their differences, let me explain. Uri:uniform Resource Identifier, Uniform Resource Identifier, Url:uniform Resource Locator, Uniform Resource Locator, Urn:uniform Resource name, Uniform Resource name. Where the URL, urn is a subset of the URI. Their relationship is as follows:

Figure 2, URI, URL, urn relationship

The basic form of an address on the web is a URI, which represents the Uniform Resource identifier. There are two kinds of forms: URL, URN. A URL is like a urn, a urn is a person's name, but a URL is like the location of the person's address. In other words, the urn defines an identifier for an element, and the URL provides a way to find it. That is, the urn is not dependent on the location, and it is possible to reduce the number of failed connections. But its popularity will take time, because it requires more sophisticated software support.

5, the current more popular Web server

Here are some of the more popular Web server software, and their 2010-year market share.

Vendor

Product

Web Sites Hosted (millions)

Percent

Apache

Apache

111

54%

Microsoft

Iis

50

24%

Igor Sysoev

Nginx

16

8%

Google

GWS

15

7%

Lighttpd

Lighttpd

1

0.46%

The Web server software I am currently researching is not in it, and the reason why I chose mongoose to study it is that there are three reasons:
    The
    • Mongoose is small, easy to use, and can be embedded in an existing application.
    • Very, very perfectly formed! Although Mongoose is small, it has the functionality that the basic Web server should have. By studying it, you can learn the features and implementation details of Web server software more quickly. The
    • Mongoose is open source and free to use.

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.