Web application and HTTP protocol

Source: Internet
Author: User
Tags telnet program

  Web applications are everywhere. Any time you browse the Web, send an e-mail or pop up an X window, you're using a web app.


Client-Server programming model

  Each network application is based on the client-server model. With this model, a server process is composed of one or more client processes. The server manages some kind of resource and provides some kind of service to its clients by manipulating it.

  It is important to recognize that the client and server are processes, not the machines or hosts that are often mentioned. A host can run many different clients and servers at the same time, and one client and server transaction can run on the same (X Window) or different host. The client-server model is the same regardless of how the client and server are mapped to the host.

 Clients and servers communicate through the global network of the Internet. From a programmer's point of view, we can see the Internet as a global collection of hosts, with the following properties: 1 Each Internet host has a unique 32-bit name, called the IP address. 2) The collection of IP addresses is mapped to a collection of Internet domain names. 3) processes on different Internet hosts can communicate with each other via a connection.

The client and the server establish a connection by using the socket interface. A socket is an endpoint of a connection. Each socket has a corresponding socket address, which consists of an Internet address and a 16-bit certificate port, denoted by "Address: Port". When a client initiates a connection request, the port in the client socket address is automatically assigned by the kernel, called the ephemeral port. However, the port in the server socket address is usually a well-known port, which corresponds to the service. For example, a Web server typically uses port 80, and the e-mail server uses port.

HTTP Overview

  The interaction between the Web client and the server is a text-based application-level protocol called HTTP (hypertext Transfer Protocol, Hypertext Transfer Protocol). The HTTP protocol is implemented by a two-part program: A client program and a server program that runs on different end systems, exchanging HTTP messages for sessions. HTTP defines the format of these messages and how the client and server are exchanging messages. What is the difference between a Web service and a regular file retrieval service (such as FTP)? The main difference is that Web content can be written in a language called HTML (hypertext Markup Language, Hyper-text markup language). An HTML Program (page) contains (tags) that tell the browser how to display various text and graphic objects on this page.

Web pages (Web page, also called documents) consist of objects that are simply files, such as HTML pages, JPEG graphics files, Java applets, or video fragment files that can be addressed through a URL address. Most Web pages contain a basic HTML file (base HTML files) and several reference objects. The object is referenced in the base HTML file through the object's URL address. Each URL address consists of two parts: the server host name that holds the object and the path name of the object. The Web browser implements the HTTP client. Web servers are used to store Web objects, and each object is addressed by a URL. The web implements the server side of HTTP, and the popular Web server has Apache and Mircosoft Internet information Sever.

  HTTP uses TCP (instead of UDP) as its support Transport layer protocol, and the default port number is 80.

HTTP transaction

  

An HTTP transaction that serves static content

Because HTTP is based on lines of text that are transmitted over an Internet connection, we can use the UNIX Telnet program and any Web server on the Internet to perform transactions. Telnet is handy for debugging a server that uses text lines on a connection to talk to clients. For example, use Telnet to request a home page from the AOL Web server.

In the first line, we ran Telnet from the Unix shell and asked it to open a connection to the AOL Web server. Telnet prints three lines of output to the Terminal server, opens the connection, and waits for us to enter a line of text (line fifth). Each time we enter a line of text and type Enter, Telnet reads the line, adds a carriage return and a newline symbol, and sends the line to the server.

HTTP request

The composition of an HTTP request is this: a Request line (line 5th) followed by 0 or more header lines. The request line has 3 fields: The Method field, the URL field, and the HTTP protocol version field. Method fields can take values of Get, POST, HEAD, put, and delete. Most HTTP request messages use the Get method. When the browser requests an object, use the Get method to fill in the URL of the object at the bottom of the URL. The example used is '/', which is the smallest URL suffix, and all servers extend it to a default home page, for example,/index.html '

The head method is similar to the Get method. When the server receives a request using the Head method, it responds with an HTTP stripe, but does not return the request object. Application developers use head for fault tracking

  When the user clicks the hyperlink, the browser initiates a TCP connection between the browser and the Web server, which involves a "three-time handshake" process in which the client sends a small TCP segment to the server, the server confirms and responds with a small TCP message segment, and the client returns an acknowledgment to the server. After completing the first two parts of the three handshake, the client sends the third part of the three handshake (client acknowledgment) and an HTTP request together to the TCP link . Once the request message arrives at the server, the server sends an HTML file to the TCP link.

HTTP response

  HTTP responses are similar to HTTP requests. The composition of an HTTP response is this: a response line (response lines) followed by 0 or more response Headers (response header) (line 9th to 13th) followed by a blank line with a terminating header (line 14th), followed by a response body (response body) (line 15th to 17th). The format of a response flight is:

<version> <status code> <status message>

The correspondence is:

http/1.0 OK

The Version field describes the HTTP version followed by the response. The status code is a three-bit integer that indicates the processing of the request. The status message gives an English description equivalent to the error code. The main status codes are as follows:

200 Success Processing requests correctly
301 Permanently moving The content has been moved to the host indicated in the location header
400 Error request The server does not understand the request
403 Ban The server is not authorized to access the requested file
404 Not found

The server cannot find the requested file

30w Not found The server does not support the requested method
505 HTTP version not supported The server does not support the requested version

Web application and HTTP protocol

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.