web ---- tcp three-way handshake

1, first of all why we need to shake hands

First we look at the structure of TCP segments

The TCP segment window field this 16 part here is to realize the role of the window to control the flow of why there is traffic control is introduced? ? ? It is to come: If the speed is greater than the sender sends the data receiving application speed of access to data (assuming the data transmission process is not congested), the receiving side Distortion phenomena occur, i.e. the data covered, Therefore, the transmission data is necessary to be controlled, on the introduction of this 16-bit window. How introduced? ?

The sender and receiver has a buffer (for receiving data coming from the network, and presented to the application), for the receiver, it should maintain the values ​​of two variables, one is read out from the cache application data (out represented); the other is receiving network data (expressed in) from the receiving side then the remaining space inside a buffer is Buffer- (in - out) = window (assuming the number of a buffer buffer represented number, in - out is the number of applications did not read, that is, the number of cache is occupied by subtracting the total of occupied space that can be used to indicate the number with window), then the window is the window to write the values, accept the party will pass this value to the sender indicate how much space I have available.

A sender will have the same cache, to maintain the same values ​​of two variables: one is the number of data already transmitted (Send); the other is the number of data (ACKed) has been confirmed, then send - acked already says sent, but has not been confirmed number of data, in other words the data being transmitted (this better understanding, but not a bit), then let the recipient buffer data is not overwritten, the data is transmitted It is smaller than the receiver window (send - acked <window).

In the process briefly about the three-way handshake:

First, the client sends TCP short message.

Second, the server sends a reply, and the establishment of buffer and variables.

Third, the client sends a reply, and the establishment of buffer and variables.

Note also that when the three-way handshake to establish a cache, that is, A B want to communicate with, a good agreement between the two must be some parameters, such as caching here, then according to the above theory, the establishment of buffer the purpose is to avoid unreliable transmission of data (that is, to prevent data from being overwritten), so before transmitting data, do some agreement between the two, in other words the first when making a deal on a good place and time, in make a deal.

So, in general, so-called link is to allocate memory and other resources, and to avoid unreliable transport, so as not to dirty the name of the first TCP reliable transmission! ! !

2. Why do I need to shake hands three times

TCP three-way handshake is the most important to prevent the spread expired connect again host is connected. If twice, then following that happens. A confidential example is connected to the machine B, result of the connection information transmitted for some reason does not reach the machine B; thus, the machine has made an A, B receives the result, and then to send back information, to connect the two machines . Through after things off. The results this time, the connection information that was previously not arrive suddenly spread to machine B, then B machine send a message to A, then A and B machine to think that even on this machine in waiting time B A pass things in the past. 2. The three-way handshake only requires two handshaking changed, a deadlock is likely to occur regardless of the communication between the computers A and B, A sends to B is assumed that a connection request packet, the received packet A, and sends acknowledgment packets. Under the agreement the two shook hands, A considers the connection has been successfully established, you can start sending data packets. However, B in the case of A reply packet is lost in transmission, and will not know whether A is ready, I do not know what kind of recommendations A serial number, B and even A doubt whether it has received its own connection request packet. In this case, B considers the connection has not been established successfully, will ignore any data packets sent by A, just waiting for the connection confirmation response packet. This creates a deadlock

 

The TCP seq

TCP byte stream transport connection in each byte are sequentially numbered, the first byte number randomly generated by the local

seq is actually the first byte in the segment data number.

For example, the sequence number field value of the packet period 200, and carrying a total of 100 data field, obviously the next segment (if there is any) should start from the data number 300;

[200, 300) of length 100! ! !

 

Guess you like

Origin www.cnblogs.com/yanxiaoge/p/11565944.html