In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article is to share with you about linux network programming tcp sticky package and how to solve, the editor feels very practical, so share with you to learn, I hope you can get something after reading this article, say no more, follow the editor to have a look.
1. What is a sticky bag?
Streaming sockets first talk about why TCP is called streaming sockets. As the name implies, it means that the data transmission of TCP is the same as flowing water. You can imagine that water is connected into one piece, it has no dividing line, and TCP data transmission is the same. There are no boundaries.
Anyone who is familiar with the TCP protocol should know that when TCP sends data, it is not sent later by the application send. It is first stored in the send buffer. For performance reasons, it may wait until multiple packets are aggregated together, and then the buffer is sent out at the bottom of the operating system, and the received data is the same.
Maximum transmission unit in network transmission, there is a MTU- maximum transmission unit, which is 1500 bytes, that is, each transmission can only send a maximum of 1500 bytes. If you want to send data packets beyond this length, you need to send them in sub-packets.
When the above three points occur, the data received by the receiver may be inconsistent with the size and number of packets sent, and we have no way to determine what a complete packet sent by the sender is like. There is no way to correctly obtain the data we need, which is the sticky packet phenomenon. In fact, the application process does not know how big a complete packet is and cannot be parsed, and the client and server need to have an agreed rule to ensure that there is no sticky packet.
two。 How to solve the sticky bag
There are three situations that can solve the sticking phenomenon:
One is to agree on the packet length, that is, the sender and the receiver agree on the same packet length to send and receive, so that the data we need can be clearly obtained.
The second is to use delimiters. For example, the smtp protocol uses\ r\ n as the delimiter when sending, but if there is also\ r\ n in the data we want to send, it is easy to get confused, so it is not recommended.
The third is to fill the length of the entire packet with 2 or 4 bytes at the beginning of each packet, so that the receiver can receive 2 or 4 bytes first, so that the receiver can know exactly how long the real packet is, so as to get the required data correctly.
The above is the tcp sticky package in linux network programming and how to solve it. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.
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: 0
*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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.