Request an HTTP page related procedure

Source: Internet
Author: User
Tags ack

HTTP request from TCP to establish a three-time handshake, the client in accordance with the prescribed format to the server to send HTTP requests, the server after receiving the request, the first to parse it, to explore the client needs of the relevant resources, and then through the corresponding business logic processing, find the corresponding resources, and returns it to the client in a specific form. Note: Both the request and the response are in accordance with the HTTP protocol in the relevant format, which is more common.

Request format for HTTP

the HTTP request format mainly includes these parts: the request line, the request header, the blank line, the message body. The concrete structure is as follows:

Request line: Refers to the first line in the request, it mainly consists of 3 parts: GET, post, such as the method name, the URI of the request resource, the version number of the HTTP used.

Information in the request header: There is information about cache-related information and client identity (user-agent).

Message body: Refers to the data resource requested by the client to the server, which is not required for each request.

Response format for HTTP

The HTTP request format mainly includes these parts: Response line, response header, blank line, message body. The concrete structure is as follows:

Response line: It contains three main parts: the HTTP version number, status code, and status description used.

Response headers: The response header is some information that the server passes to the client to describe the server and the policy when it continues to access the resource in the future.

Message body: Refers to the server to the client to respond to the HTML file, or other forms of content, such as video files, pictures and so on.

Socket

HTTP page request This part of the content is closely related to socket programming, also known as Network programming, network protocol through a socket called the object abstraction, socket can establish network connection, read data, write data. The socket module defines a number of constant parameters that specify the address family of the socket, the type of socket, and the supported TCP/IP protocols.

Socket.socket ([family[, type[, Proto]]): Creates a socket object based on the specified address family and socket type, protocol number (default = 0). Af_inet corresponds to the IPV4, Af_inet6 corresponds to the IPV6. Now the most common is the IPV4 protocol. The specific parameters are assigned as follows:

server-side programming (ser):

Socket : Establish the desired type of communication protocol. af_inet :IPV4, now the most used. sock_stream : Streaming sockets.

Bind () Ip:port: Assigns a local protocol address to the socket interface, and for TCP, the calling function bind can develop a port number, Used to identify a process on a computer, it can also specify an IP address

Listen: Called only by the TCP Server, which is a Client socket interface that will invoke connect to initiate a connection that indicates the connection request that the kernel points to this set of interfaces. The function is called before Accpect. For a listening socket interface, the kernel must maintain a queue: the status of the connection queue and the completed connection queue are not completed.

Accept: Returns the next completed connection from the completed connection queue header and goes to sleep if the completed connection queue is empty. If accept executes successfully, the connection to the customer is successful

Recv/read: Receives the information sent by the client.

Send/write: Returns an OK to the client ;

Close: Closes the connection.

Client CLI:

Socket: Establish the desired type of communication protocol. af_inet :IPV4, now the most used. sock_stream : Streaming sockets.

Connect: Establish a link to the server. The client does not have to call bindbefore calling Connect, andif it is a TCP socket, the function Connect Inspire TCP three handshake process and only returns if the connection is established or incorrect

Send: sends a message to the client. It can only be explained that the data has been successfully written to the send buffer, not necessarily the arrival.

RECV: Receives the OK that the client sends over .

Close: Perform si ' ci ' hui ' shou

GetSockName and getpeername return the local protocol address associated with the socket interface. getsockname can be used to obtain an address family for a set of interfaces. on a client thatdoes not call bind, whenconnect returns successfully,Getsocknam Returns the local port number and IP address assigned to this connection by the kernel .

Three-time handshake

The most initial client and server TCP processes they are in the closed state, first, the TCP server process of B first created the Transport control block TCB, ready to accept the client's connection request, and then the B server process side is in the listen state, Waits for a connection request from the client. Then a TCP client process is also the first to create a Transmission control module, and then send a connection request packet to B, the header of the message segment syn=1, and set itself an initial amount of s, at this time the client process into a send state is the synchronization sent state. Then, when B receives a connection request from a, it agrees to establish the connection and needs to send a confirmation to a. That is, the SYN and ACK are set to 1, the confirmation number is ack=s+1, also should send a own initial value is assumed to be N, at this time B enters the synchronous receive state. When client A finally receives B's acknowledgment, it should also issue a confirmation to B, set the ACK to 1, and the ACK to n+1, and then a to enter established to establish the connection state. After B receives a confirmation, also enters the established state. As shown in the following:

Wave four times

AProcess first toTCPissue a connection release message segment, and stop sending data, active shutdownTCPconnection, you need to terminate the control bitFINReset to1, and set its initial valueU, thenAEnter termination wait1status, WaitingBthe confirmation. Bsend confirmation immediately after receiving the link Release message section, confirmation numberack=u+1, the exception sets an initial value of its ownv, and thenBJust enterclose-waitstate. WhenTCPafter you notify the high-level application, thenAand theBthe connection between them is released, but at this pointTCpin a semi-closed state, i.e.Ato theBthe connection between them was released, butByou can also sendAsend data,AreceivedBafter the confirmation, enter the termination wait2status, WaitingBThe connection release message segment issued. AssumptionsBSend a connection release segment, the control bit will be terminatedFINReset to1and issue a confirmation number at the same timeack=u+1,and set one of your own initial values toW, and thenBIt's in the final confirmation state.Last-ack,waitAthe confirmation;AreceivedBafter the link releases the message segment,Bissue a confirmation that theACKReset to1, the confirmation number is placedw+1, and thenAJust entertime-waittime wait state. , whenAWaiting on2MSLafter the longest message segment life,4SEnterCLOSEDstatus to start the next new connection establishment.

Request an HTTP page related procedure

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.