Method for solving TCP network packet sticking problem
Through the method of pre-reading data and lightweight data verification, it solves the problem of TCP network packet sticking, reduces the number of memory copies and the risk of memory overflow, and improves data transmission efficiency. It is especially suitable for TCP and audio and video transmission fields.
Patent Information
- Application Number
- CN202410948389.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-16
- Publication Date
- 2024-09-10
AI Technical Summary
Existing TCP network packet sticking solutions have low efficiency and risk of memory overflow during retransmission and data parsing, and affect the efficiency of escaping and parsing data headers.
By pre-reading the data into the buffer, it determines the data header identifier and ensures that the data length is correct before parsing to avoid memory overflow. When the data is abnormal, the abnormal data is discarded to ensure the correctness of subsequent parsing and reduce the number of memory copies.
It effectively solves the problem of sticky packets in TCP networks and improves data transmission efficiency. Especially in the fields of TCP and audio and video transmission, it reduces the complexity of data verification and improves system performance.
Smart Images

Figure CN118631398A
Abstract
Description
Technical Field
[0001] The invention relates to the technical field of building intercom, in particular to a method for solving the TCP network packet sticking problem. Background Art
[0002] The existing method for solving the TCP network packet sticking problem is to discard the stuck packets and retransmit them, and respond when a complete packet is received. Once a stuck packet is found, it is discarded and no response is given. If the sender does not receive a response, it retransmits. This method will increase the network load to a certain extent, and there is no guarantee that the sticky packet will not appear again after retransmission. In addition, the start code and the end code are added, and the start code and the end code need to be escaped. After parsing, the packet needs to be escaped, which affects efficiency. The length header is added to the header, and it is necessary to ensure that all data is normal. Once a packet abnormality occurs in the middle, it will affect the parsing of all subsequent packets. Summary of the invention
[0003] 1. Technical issues to be resolved In view of the deficiencies in the prior art, the present invention provides a method for solving the TCP network packet sticking problem.
[0004] (II) Technical solution To achieve the above object, the present invention provides the following technical solution: A method for solving the TCP network packet sticking problem, comprising the following steps: Step 1: Pre-read data into the buffer; Step 2: When the pre-read data does not exceed the data header length, continue pre-reading and let the other end continue to send data; Step 3: It is very important to judge the identifier. Only when the data header contains the identifier can it be proved to be a legal data header. If the identifier is incorrectly identified, the length of the obtained data may be incorrect, and then the wrong data may be parsed; Step 4: If the identifier is not read, it means that the data is abnormal and the abnormal data is discarded; Step 5: Read the data header; Step 6: If the length of the packet header exceeds the limit, in order to avoid memory overflow, the current parsing needs to be abandoned; Step 7: After parsing the data length field, for example, L bytes, you can continue to read L characters into the receiving buffer. At this time, it can be guaranteed that the data in the buffer is non-sticky data, and there is no need to use collection, queue, or frame removal like other patents.
[0005] Furthermore, the present invention has the following improvements: the pre-reading in the first step will not affect the actual reading. For example, if the other end sends ABC, we pre-read a character A, and when we actually read, we still get ABC.
[0006] Furthermore, the present invention has the following improvements: in the second step, for a lightweight solution, the data header only occupies 5 bytes (0x7e plus 4 bytes in length) or 8 bytes (0x00x00x00x1 plus 4 bytes in length).
[0007] Furthermore, the present invention is improved in that the data is discarded in the fourth step to ensure that the error can be recovered. As long as the subsequent data format is correct, normal data parsing can be restored when the data header identifier is parsed again.
[0008] Furthermore, the present invention is improved in that the fifth step is to read the data length field in the data header for subsequently receiving data of a specified length.
[0009] Furthermore, the present invention has been improved in that, in order to prevent abnormal packet headers from appearing, for example, the other end writes an incorrect packet header length, the current parsing is skipped in the sixth step and the next round of parsing is entered.
[0010] (III) Beneficial effects Compared with the prior art, the present invention provides a method for solving the TCP network packet sticking problem, which has the following beneficial effects: 1. Data pre-reading technology: After pre-reading data, subsequent sticky packets can be directly and completely retrieved, reducing the number of memory copies; 2. Use lightweight data verification. Especially for TCP and audio and video transmission, strict data verification is not required. Using lightweight verification solutions can improve efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0011] Figure 1 It is a system schematic diagram of the present invention. DETAILED DESCRIPTION
[0012] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0013] See also Figure 1 A method for solving the TCP network packet sticking problem of the present invention comprises the following steps: Step 1: Pre-read data into the buffer. The pre-reading here will not affect the actual reading. For example, if the other end sends ABC, we pre-read a character A, and when we actually read it, we still get ABC. If we do not use the pre-reading technology here, and directly read the entire buffer into buf1, such as ABCDabc, ABCD is a package, abcd is another package, and these two packages are glued together, then we need to use another piece of memory buf2 to store the ABCD package, and then we need to move abc to the beginning of buf1, and then continue to read dEFG. A total of three memory operations are required, which is two more memory operations than the pre-reading solution; Step 2: If the pre-read data does not exceed the data header length, continue pre-reading and let the other end continue to send data. For lightweight solutions, the data header only occupies 5 bytes (0x7e plus 4 bytes) or 8 bytes (0x00x00x00x1 plus 4 bytes). In general, as long as the data header is sent from the other end, the data exceeding the data header length can be received. Step 2 is for logical rigor to prevent the small probability of incomplete data header.
[0014] Determine whether the pre-read data contains the packet header identifier. This is used to verify whether the expected data is received. For example, a single-byte 0x7e is used as an identifier, or a video header 0x00x00x00x1 (or 0x00x00x1) sequence is used as an identifier. For video, the advantage of using the video header is that the video bitstream has already made a unique guarantee for 0x00x00x00x1. The principle of this guarantee is that if 0x00x00x0 appears in the video bitstream, it will be replaced by 0x00x00x30x0, if 0x00x00x1 appears, it will be replaced by 0x00x00x30x1, if 0x00x00x2 appears, it will be replaced by 0x00x00x30x2, and if 0x00x00x3 appears, it will be replaced by 0x00x00x30x3. The video will be reversed when parsing. This ensures that 0x00x00x00x1 (or 0x00x00x1) will not appear in the video bit rate. Based on this uniqueness, it can be guaranteed that when the data header is parsed to 0x00x00x00x1 (or 0x00x00x1), it must be a unique video header. For scenarios where 0x7e is used as the packet header identifier, when the data stream contains 0x7e, it needs to be converted to 0x7d0x5e. When encountering 0x7d, it is converted to 0x7d0x5d, and then the inverse transformation is performed during parsing. This ensures the uniqueness of the data stream identifier. For scenarios where data verification is not strict, the data stream can be escaped without escaping, and only identifiers such as 0x7e can be used to improve efficiency. In addition, the data stream can also be not escaped. For video transmission, the cost is that there may be freezes or screen distortion, but the efficiency is higher; Step 3: It is very important to judge the identifier. Only when the data header contains the identifier can it be proved to be a legal data header. If the identifier is incorrectly identified, the length of the obtained data may be incorrect, and then the wrong data may be parsed; Step 4: If the identifier is not read, it means that the data is abnormal and the abnormal data is discarded. The data is discarded here to ensure that the error can be recovered. As long as the subsequent data format is correct, when the data header identifier is parsed again, normal data parsing can be restored; Step 5: Read the data header. This is to read the data length field in the data header, which is used to receive data of the specified length next. Step 6: If the length of the packet header exceeds the limit, in order to avoid memory overflow, the current parsing needs to be abandoned. This is also to prevent abnormal packet headers. For example, if the other end writes the wrong packet header length, the current parsing will be skipped and the next round of parsing will be entered; Step 7: After parsing the data length field, for example, L bytes, you can continue to read L characters into the receiving buffer. At this time, it can be guaranteed that the data in the buffer is non-sticky data, and there is no need to use collection, queue, or frame removal like other patents.
[0015] The above process is to obtain the actual length of a transmission. With this length, no other memory copy is required to obtain complete data, which improves efficiency. In the content of this application, the data pre-reading technology pre-reads the data so that the subsequent sticky packets can be directly and completely retrieved, reducing the number of memory copies.
[0016] Use lightweight data verification, especially for TCP and audio and video transmission, which do not require too strict data verification. Using lightweight verification solutions can improve efficiency.
[0017] In the description of this article, it should be noted that relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device.
[0018] While the embodiments of the present invention have been shown and described, it will be appreciated by those skilled in the art that many changes, modifications, substitutions and variations can be made to the embodiments without departing from the principles and spirit of the invention.
Claims
1. A method for solving the TCP network packet sticking problem, characterized in that: It includes the following steps: Step 1: Pre-read data into the buffer; Step 2: When the pre-read data does not exceed the data header length, continue pre-reading and let the other end continue to send data; Step 3: It is very important to judge the identifier. Only when the data header contains the identifier can it be proved to be a legal data header. If the identifier is incorrectly identified, the length of the obtained data may be incorrect, and then the wrong data may be parsed; Step 4: If the identifier is not read, it means that the data is abnormal and the abnormal data is discarded; Step 5: Read the data header; Step 6: If the length of the packet header exceeds the limit, in order to avoid memory overflow, the current parsing needs to be abandoned; Step 7: After parsing the data length field, for example, L bytes, you can continue to read L characters into the receiving buffer. At this time, it can be guaranteed that the data in the buffer is non-sticky data, and there is no need to use collection, queue, or frame removal like other patents.
2. A method for solving the TCP network packet sticking problem according to claim 1, characterized in that: The pre-reading in the first step will not affect the actual reading. For example, if the other end sends ABC, we pre-read a character A, and when we actually read it, we still get ABC.
3. A method for solving the TCP network packet sticking problem according to claim 2, characterized in that: In the second step, for the lightweight solution, the data header only occupies 5 bytes (0x7e plus 4 bytes of length) or 8 bytes (0x00x00x00x1 plus 4 bytes of length).
4. A method for solving the TCP network packet sticking problem according to claim 3, characterized in that: The purpose of discarding data in the fourth step is to ensure that the error can be recovered. As long as the subsequent data format is correct, normal data parsing can be resumed when the data header identifier is parsed again.
5. A method for solving the TCP network packet sticking problem according to claim 4, characterized in that: The fifth step is to read the data length field in the data header to receive data of the specified length.
6. A method for solving the TCP network packet sticking problem according to claim 5, characterized in that: In the sixth step, in order to prevent abnormal packet headers, such as the other end writing the wrong packet header length, this round of analysis is skipped and the next round of analysis is entered.
