HTTP protocol-----> Connection Management

Source: Internet
Author: User

1. TCP Connection 1.1 TCP provides a reliable way for HTTP bit Transport Pipeline

  TCP (transmission Control Protocol)----Transmission protocol, is the host-to-host layer of Transmission Control Protocol, providing reliable connection services. the data for TCP is sent through small chunks of data called IP packets (or IP datagrams) . The HTTP/HTTPS network protocol stack looks like this:

    1. When HTTP receives a message, the message data content is converted into a stream form;
    2. Data flows over an open TCP connection in sequential transmission ;
    3. TCP receives the data stream and cuts the data stream into a small chunk of data called a segment;
    4. Enclose the small data block in the IP ;
    5. Through the Internet to complete the transmission ;

  TCP segments are hosted by an IP packet (represented as a parameter to a segment of TCP)and sent from one IP address to another IP address. Each of the IP groupings includes:

    1. An IP packet header (usually 20 bytes)---> contains the IP address, length, and other tokens of the source and destination;
    2. A TCP segment header (usually 20 bytes)---> A numeric value that contains the TCP port number, TCP control token, data ordering, and integrity checking;
    3. A TCP data block (0 or more bytes)---> stream of packets to be transmitted;

TCP Segment #x

  A TCP connection is identified by four values:

< source IP address, source port number, destination IP address, destination port number >

  TCP Fragmentation The transmission is as follows:

1.2 TCP Socket Programming

Pseudo-code describes the steps that are performed when the client and server implement HTTP transactions through the socket API:

1.3 TCP Three handshake four times wave (Focus!!!) )

  You know!!! What is a three-time handshake, why not two times? What is a four-time wave? Why not join the 23rd wave?

First talk about the TCP flag, there are 6 kinds of signs:

    1. SYN (Synchronous set up online)
    2. ACK ( Acknowledgement confirm)
    3. PSH (push transfer)
    4. < Span style= "LINE-HEIGHT:19.2PX;" > FIN (finish end)
    5. < Span style= "LINE-HEIGHT:19.2PX;" > RST (reset reset)
    6. < Span style= "LINE-HEIGHT:19.2PX;" > URG (urgent emergency)

  Three-time handshake, data transfer, four wave graphs:

  

then why do you need to shake hands three times? Based on the procedure shown, the following:

    1. Client C initiates a connection request to server S:c-->s;
    2. Client C receives a send signal from the server S and sends a confirmation message to client C:s-->c;
    3. Client C receives a confirmation signal from the server s and sends a confirmation signal to s: c-->s.

  The three-time handshake is probably a process like this:

    1. With the first handshake, the server s knows that client C can send data.
    2. With the second handshake, client C knows that the server S can receive and transmit data.
    3. In conjunction with the third handshake, server s knows that client C can receive data.

At this point, the handshake process is complete, the client C know that the server S can receive the energy, the server s know that client C can receive and send, the communication connection is established.

  Two points: (To know!!!)

  1. Three times the completion of the handshake, just a client C and server S can establish a connection between the confirmation process , has not been a real data block transmission, data block transmission is in three times after the completion of the handshake things;
  2. UsingTwo-time handshake may have a failure conditionClientthe connection request did not receive confirmation from the server (no second handshake), so after a period of time, the client then re- sends a new connection request to the server, and establishes the successful, sequential completion of the data transfer. Consider such a special case, the first time the client sends a connection request is not lost, but because the network node caused the delay to reach the server , the server thought it was a new connection initiated by the client, so the server agreed to connect, and to the client Send back a confirmation, but at this point the client does not care, the server has been waiting for the client to send data, causing the server to waste resources. The three-time handshake is guaranteed to be a reliable minimum handshake number, and multiple handshakescan not improve the probability of communication success, but waste resources.

four times to wave, combine, see the following procedure:

    1. Client C initiates a request to server S, which indicates that client C has no data to send:c-->s;
    2. Server S sends a signal to client C to confirm client C's Disconnect request:s-->c;
    3. The server s sends a signal to client C and requests a disconnection, indicating that the server S has no data to send:s-->c;
    4. Client C sends a confirmation signal to server S and agrees to disconnect: C-->s.

The server S receives a confirmation signal, disconnects, and the client loses a signal to the server for a period of time, indicating that the server s has been disconnected, and client C is disconnected. At this point, complete the wave process.

  Why do you need to wave four times, the second third wave can be combined Wow????

Of course you can't! Wave and shake a similar, confirm the disconnection process, but, wave to one more to confirm the data disconnection, not only to confirm the disconnection of the connection, so more than a handshake. Handshake----> Connection creation; wave----> Disconnection of the connection + data disconnection (more than one time).

HTTP protocol-----> Connection Management

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.