In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
In this issue, the editor will bring you about the methods of tcp long connection subcontracting. The article is rich in content and analyzes and describes for you from a professional point of view. I hope you can get something after reading this article.
There are four methods of tcp persistent connection subcontracting, which are: 1, the method of fixed message length, 2) the method of using a special string as the message boundary, 3) the method of adding a length field to the header of each message, and 4) the method of subcontracting using the format of the message itself.
There are four methods for tcp persistent connection subcontracting:
1. The message length is fixed.
two。 Use a special string as the message boundary. For example, the headers of the http protocol uses "\ r\ n" as the field delimiter
3. Add a length field to the header of each message. This is the most common.
4. Subcontract using the format of the message itself. Such as peer-to-peer in xml
Talk about the method of subcontracting the message length field in the header.
If each message has a 4-byte header, store the length of the string. For example, for the message "hello", the byte stream is 0x00rec 0x00je 0x00je 0x00je 0x05jinhrew.
Write a piece of pseudo code to show the subcontract:
Void OnMessage () {while (receive buffer buf readable bytes > = header length 4) {len= packet length if (len > 65536 or len=len+4) {extract 4 bytes from buf Message= assigns the len length memory after buf to message messagecallback (message). Call the user code to process message to remove the len length from the buf. Else {not enough for the length of a packet, wait for the next message to arrive, break } the above are the methods of tcp persistent connection subcontracting shared by Xiaobian. If you happen to have similar doubts, please refer to the above analysis to understand. If you want to know more about it, you are welcome to 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.