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:
- When HTTP receives a message, the message data content is converted into a stream form;
- Data flows over an open TCP connection in sequential transmission ;
- TCP receives the data stream and cuts the data stream into a small chunk of data called a segment;
- Enclose the small data block in the IP ;
- 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:
- An IP packet header (usually 20 bytes)---> contains the IP address, length, and other tokens of the source and destination;
- A TCP segment header (usually 20 bytes)---> A numeric value that contains the TCP port number, TCP control token, data ordering, and integrity checking;
- 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:
- SYN (Synchronous set up online)
- ACK ( Acknowledgement confirm)
- PSH (push transfer)
- < Span style= "LINE-HEIGHT:19.2PX;" > FIN (finish end)
- < Span style= "LINE-HEIGHT:19.2PX;" > RST (reset reset)
- < 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:
- Client C initiates a connection request to server S:c-->s;
- Client C receives a send signal from the server S and sends a confirmation message to client C:s-->c;
- 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:
- With the first handshake, the server s knows that client C can send data.
- With the second handshake, client C knows that the server S can receive and transmit data.
- 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!!!)
- 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;
- 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:
- Client C initiates a request to server S, which indicates that client C has no data to send:c-->s;
- Server S sends a signal to client C to confirm client C's Disconnect request:s-->c;
- 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;
- 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