Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

TCP three-way handshake, confused window, sticky bag problem

2025-04-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

Shulou(Shulou.com)06/01 Report--

This is the summary in the study. If there are any mistakes, please do not hesitate to correct (^. ^)

About the three-way handshake for TCP/IP:

When the status of the server is LISTEN and the status of the client is CLOSED, the client initiates a connection

The client sends a SYN field message, and the status is SYN_SENT.

When the server receives the message, it is in the SYN_REVD state and sends the message with SYN and ACK fields to the client.

When the client receives the message, it is in the ESTABLISHED state and sends the message with the ACK field.

After receiving the message, the server is in the ESTALISHED state and starts the data exchange.

About the confused window:

In network data transmission, a large number of messages containing a small amount of data are sent (in extreme cases, a message has only one byte of data), because the data is encapsulated layer by layer in the protocol layer, so there are a large number of protocol headers for the data. the transmission overhead is too high, or the receiver is too slow to accept data in the cache area.

Solution:

The sender uses the Nagle algorithm. When the packet length is less than the MSS size, it will wait for a while. The sending condition is:

Until all packets sent have ACK replies and TCP_CORK is not set

Until there is a FIN field

Until the data length reaches MSS

Until the wait timeout (normal 200ms)

When TCP_NODELAY is set and TCP_CORK is not set; (that is, no optimization algorithm is used)

(the algorithm is not very useful when the ACK field of the packet is received quickly.)

The sender uses the CORK algorithm to splice small packets into large packets, which reduces the proportion of the protocol header in the protocol message. The sending conditions are:

The spliced message is larger than MTU or timed out

When TCP_CORK is not set and TCP_NODELAY is set; (that is, no optimization algorithm is used)

(when the transmission interval of the packet is not short, it affects the real-time performance, because you have to wait for the timeout transmission.)

The receiver uses Clark to confirm as soon as any data arrives, but declares the window size to be 0 until the cache space is large enough to hold a MSS or half of the cache space is empty.

The receiver delays the acknowledgement until the cache space is sufficient, preventing the window of the TCP sender from sliding, which can reduce the traffic and do not have to confirm each message segment, but the delayed acknowledgment will lead to retransmission.

About the sticky package:

In order to solve the confused window, the data is accumulated and sent, or the receiver does not accept the cache data in time and receives multiple packets at the same time, which will cause the original data sent to be spliced together.

Solution:

When the data transmission is disconnected immediately after an interaction (multiple Client and one Server), when the data is unstructured (file transfer, one party sends and the other receives), there is no sticking packet problem when using UDP (with message boundary).

The sender sets up to force data to be sent immediately without having to wait for the cache to be full (no processing optimization, reduced efficiency)

The receiving efficiency is improved by optimizing the programming method of the receiver, simplifying the receiving process, increasing the receiving priority, etc. (can not be completely avoided)

The receiver receives several times according to the structure field and artificial control, and then merges (inefficient and not suitable for real-time situations)

Ask here, how to beautify it? it was cool to read other people's blogs before.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 214

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Network Security

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report