Getting Started with TCP/IP

Source: Internet
Author: User

TCP/IP is a protocol cluster, not just TCP and IP protocol, here we mainly talk about TCP protocol in Transport layer

1:TCP, IP seven layer, four-layer model


Why are there seven-and four-tier models, and why are there so many layers to be designed?

Network data is sent from the end to the receiving end, the process involved in the middle is very cumbersome, in order to ensure that the data can reach the destination, but also to ensure that the system processing data will not be too complex, so the idea of a divide and conquer, each layer is responsible for only part of the function, the lower level to provide services, so that each layer, Neither makes the implementation too complex, but also guarantees the data transmission.

In fact, at the beginning of the seven-tier model is proposed by the ISO (International Organization for Standardization), the seven-tier model is very good, but in the actual use of the process, it is too cumbersome, and four-tier model more practical, so usually we are contacted by the four-tier model.


3: Problems encountered in network transmission (TCP protocol appears)

The lower level provides services for the upper floors, each layer of their respective responsibilities, what they have done each layer, we are here only to say the network layer and above.

The network layer is responsible for addressing, ensuring that data is delivered to the destination.

When the data arrives, how the data is transmitted, how it interacts, whether the data is incorrect, and whether it is reliable, is guaranteed by the transport layer.

Transport layer is divided into TCP and udp,tcp is a connection-oriented protocol (analogy Ropeway, the transmission of data rely on the ropeway, because there is a ropeway, so the data, in the transmission process will not appear to be lost), to ensure reliable data transmission, how to do the following we will talk about.


UDP is a connectionless form (analogy toss, the data transfer process does not have an effective guarantee), so he can not guarantee that the data will not be lost,





Application layer when the data arrives in our application and needs to be processed by our application, the application needs to be processed, the connection is set up and closed, the data is decoded, the data is processed, and this layer is also the main work in the writing of the application.

4 TCP How to guarantee the transmission of data reliability

4.1 TCP three times handshake

Three times handshake is a guarantee of connection establishment, he has ensured that both sides of communication are no problem.


Why to shake hands three times, because only through three handshake to determine the communication between the two sides is no problem, can imagine two person's dialogue, a to B said, "The weather is good today ah", if B does not reply, then B may not hear, if B reply: "Yes ah", then represent B can hear, It is no problem to note that B's Receive message function. When a received a B reply, stating that A's receipt and outgoing message function is no problem, but B is not sure of their own message is no problem, so at this time a back to a syn.


Why three times instead of two times and four floors

In fact, in the process of sending the package, if there are only two times, once a request arrives at the server, the service side considers the request valid and then establishes the connection, which in turn can cause a waste of resources because, in the course of data transmission, some packets are delayed and the last connection is disconnected. This packet arrives at the server, if not three handshake, but two times, the server will set up the connection for this invalid packet, and finally lead to waste of resources. Official explanation: Prevent the failure of the connection request message segment is suddenly transferred to the host.


Three times handshake to establish the connection, how to ensure the reliability of the data (confirm the answer)



At every time the data is sent, the server, will give a confirmation response (ACK), if for some reason, the data sent is lost, you can request its resend, if the sender did not receive an ACK, the sender will resend (which involved a time interval, how long to receive ACK reply, The need for a postback, which will be based on the situation of the network to do a calculation, and then determine the time interval, not expanded here.


So how to guarantee that sent the data is orderly, this will be the serial number out, the sender, can not send a data, will carry a serial number, when the receiver received this serial number, will give the sender a next need to send the starting serial number, the sender according to the serial number again send the next batch of data.


This ensures the orderly nature of the data.


5 How to ensure the efficient transmission of TCP

Confirming the response and serial number guarantees the reliable and orderly transmission of the data, however, each packet requires its ACK, and if the packet's round-trip time is longer, the performance of the communication is lower.

So, the concept of sliding window is introduced.

The function of the sliding window is that the two sides of the communication define a number of Windows and the maximum message length (MSS) that each window allows to send, and the message is sent in MSS, and then sent as the amount of data in the entire window. For example, we define a 4 window, the MSS for each window is 1000 standard, then when sending, the process is as follows:




Even in reply Ack, because an ACK is lost, as long as the last ACK is not lost, you can determine packet transmission is no problem, but also improve the transmission efficiency of the data.

In the previous confirmation response, we used "time interval" to determine whether the package needs to be resend, and in the sliding window we can confirm that the package needs to be resend, for example, when the sender does not receive the data after sending the 1001th to No. 2000 part of the data, Because the sender does not need to wait for an ACK after sending every data. So he will send out all the data in the remaining window, but the receiver, because did not receive 1001-2000 this paragraph of data, so the return ACK is always an ACK (10001), when the data of the three ACK is the same, The sender will resend the missing packet. Compared to the previous "time interval" judgment, the sliding window will be more timely processing of lost packets.

The sliding window also provides flow control, TCP three handshake, and in the process of data transfer, in addition to confirming the next serial number sent, as well as the size of each send data segment (MSS), send and receive each given an MSS, and then select the smallest one as the smallest unit of transmission. The size is also resized during data transfer.


6 Congestion control of TCP

Because of the TCP sliding window, the transmission efficiency of the data segment is improved, but it is possible to generate problems if a large amount of data is sent at the beginning of the communication. Because the computer network is in a shared environment, because the other host reason has caused the network congestion, at this time if send a large amount of data, it is possible to the network paralysis.

So the TCP startup process is a slow-start process.

At the beginning of the start, set the size of the congestion window is 1, when the confirmation response, the size of the congestion window multiplied, the speed of network transmission began to increase gradually, but with the network congestion occurs, throughput will also speed down. And then again into the process of slowly increasing throughput



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.