Core points of Knowledge:
1. Three-time handshake: seq and ACK number
2. Wave four times: fin and random number
One, TCP/IP protocol
The TCP/IP protocol (Transmission Control protool/internet Protool) is called the Transmission Control/Internet Protocol, also known as the Network Communication protocol.
This protocol is the foundation of Internet, the TCP/IP protocol is the basic protocol used in the network.
Although the TCP/IP protocol (Transmission Control Protocol/Internet Protocol) is the name, TCP/IP is actually a set of protocols,
Includes hundreds of various features of the protocol, such as: remote login, File transfer and e-mail, etc.,
The TCP protocol and IP protocol are the two basic important protocols to ensure data integrity transmission.
Generally speaking, TCP/IP is a protocol cluster, not only TCP and IP,TCP protocol is widely used, it is the only protocol system used by heterogeneous network communication,
Suitable for connecting various models, can be used for LAN, also can be used for WAN.
TCP/IP is composed of many different protocols, TCP User Data reporting protocol, also known as TCP Transmission Control Protocol (Transport protool reliable host-to-host layer protocols),
Transmission Control Protocol is the fourth layer of the OSI network, and TCP Transmission Control protocol is one of the 6 basic protocols for TCP/IP transmission.
Two TCP meaning is not the same, TCP is a reliable connection-oriented transport service, it is in the transmission of data is segmented, the host Exchange data must establish a dialogue.
It uses bits to circulate the letter, that is, the data is used as a non-structured byte stream, specifying the sequence number through the TCP transmission field to obtain the reliability,
is the fourth layer of the OSI Reference Model, which provides reliable data transmission using IP-based inter-network Internet functionality,
IP keeps messages on the network, and TCP is responsible for determining the arrival of messages,
In the operation of the cooperative IP TCP is responsible for: handshake process, message management, flow control, error detection and processing (control),
The order of the non-normal sequence of messages can be rearranged according to a certain number sequence.
There are only two transport protocols, one is reliable transport protocol (TCP) and one is unreliable transport protocol (UDP).
About the TCP protocol can be viewed:
Http://www.cnblogs.com/yangmingxianshen/p/7900531.html
Http://www.cnblogs.com/yangmingxianshen/p/7787281.html
Tertiary shook hands and waved four times
1. Three-time handshake: establishing a connection
TCP is the Transmission Control protocol to the host layer, providing a reliable connection service, using three-time handshake confirmation to establish a connection, the bit code is the flag bit of TCP.
Some noun explanations:
- SYN: Establish online, identify status
- ACK: Confirm, identify status
- PSH: Transfer
- FIN: End
- RST: RESET
- URG: Emergency
- Sequence Number: Sequential numbers
- Acknowledge Number: Confirmation No.
First handshake: Host A sends the bit code to syn=1, randomly generates a SEQ number=1 (assuming) packet to the server, Host B is known by syn=123456, and host a requires a connection.
Second handshake: Host B receives the request to confirm the online information, sends an ACK number= (host A's seq+1) to a, syn=1,ack=1, randomly generates a SEQ number=654321 packet.
Third handshake: Host a after receiving check ACK number is correct, that is, the first sent Seq Number+1, and the bit code CK is 1, if correct, host A will send an ACK number= (Host B seq+1),
Ack=1, Host B received, confirm the SEQ value and ack=1, if the connection is successful, you can start to transfer data.
The key to the three-time handshake is the SEQ and ACK number above, and the first two handshakes randomly generate a SEQ random count, which determines the next Ack number= (seq+1),
And the SYN and ACK can be considered as a state, A to B needs to send a request, B to a also to send a request, so the first two handshakes are SYN,
The first handshake is the initiating state, so there is a confirmation ack and an ACK number two times later.
2. Wave four times: disconnect
The above describes how TCP requests are connected through three handshakes, and now explains how TCP requests are disconnected through 4 recoveries, and how to ensure the integrity and security of the data.
Since the TCP connection is full-duplex, each direction must be closed separately, and the principle is to send a fin to end the connection when the party finishes its data-sending task.
Receiving a fin means that there is no data flow in this direction, a TCP connection can still send data after receiving a fin, and the first one to close will perform the active shutdown while the other side performs a passive shutdown.
Now assume that a to B data transfer is complete:
The first wave: a sent to B a fin, the flag data has been transferred, used to close a to B data transfer, but also send a random number m, similar to seq.
Second wave: B after receiving the message will return a ack=m+1 to a, indicating that it has been received.
Third Wave: When B's data transfer is also finished, B will also send a fin to a, notify a has been transmitted, but also send a random number n.
Wave for the fourth time: A after receiving the message, return a confirmation message, ack=n+1 to B, notify B himself has received. At this point both sides are disconnected, marking the end of the entire TCP session.
Four waves is actually two times a one-time disconnection, why need this, so as to ensure the integrity of the data.
Why three handshakes, four waves?
The first thing to note is that the disconnection is not continuous, in order to ensure that the integrity of the data must be: Request + confirm the mode, so the disconnection is 4 times,
The process of establishing a connection is continuous, two requests + one acknowledgment, so it is three times.
Three-time handshake and four wave-waving mechanism for TCP protocol