A method for avoiding TCP message transmission of sticky packets and a processing terminal
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- GUANGZHOU BAOLUN ELECTRONICS CO LTD
- Filing Date
- 2023-06-25
- Publication Date
- 2026-05-12
AI Technical Summary
Existing TCP packet processing technologies are prone to packet merging when separating data packets, resulting in low processing efficiency and easy packet loss.
By using a custom fixed-length header, TCP packets are separated using conditions one and two. Condition one checks if the byte array is empty and its length is less than the preset header length, while condition two checks if the starting byte is the protocol header and if subsequent bytes do not exceed the range, thus ensuring data packet integrity.
It improves the reliability and efficiency of TCP packet processing, avoids packet fragmentation, and ensures data packet integrity.
Smart Images

Figure CN116668562B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of TCP packet processing technology, specifically a TCP packet transmission method and processing terminal that avoids packet fragmentation. Background Technology
[0002] In computer network communication, TCP is a reliable, connection-oriented transport layer protocol primarily used for data transmission between different computers. During TCP communication, the message is the basic unit of data transmission. The message length is not fixed, and the receiving end needs to separate multiple data packets from the byte array after receiving the TCP message. However, if unprocessed TCP messages are directly separated, packet merging often occurs, leading to data transmission errors. Furthermore, some existing TCP message processing techniques often separate messages by iterating through each byte of the received TCP message to check if it meets specific conditions. This method can avoid packet merging to some extent, but it is inefficient and prone to data loss. Therefore, a TCP message processing technique that is efficient, less prone to data loss, and avoids packet merging is needed. Summary of the Invention
[0003] To address the shortcomings of existing technologies, the purpose of this invention is to provide a TCP packet transmission method and processing terminal that avoids packet fragmentation, which can solve the problems described in the background art.
[0004] The technical solution to achieve the objective of this invention is: a TCP packet transmission method that avoids packet fragmentation, comprising the following steps:
[0005] Step 1: Receive the byte array recBytes containing TCP packets;
[0006] Step 2: Determine if the currently received byte array recBytes satisfies condition 1. If yes, return the listBytes collection and end the processing. The listBytes collection is initially empty. If not, continue to step 3. The listBytes collection is used to store valid data packets in the TCP segment.
[0007] Condition 1: The byte array recBytes is empty and its length is less than the preset message header length JudgeBytes;
[0008] Step 3: Iterate through each byte in the byte array recBytes. Starting from the first byte, determine if the current byte meets condition two. If it does, combine all bytes from the current byte to the byte shifted forward by a preset byte length to form a valid data packet, and store the valid data packet in the listBytes set. Then, use the byte shifted forward by the preset byte length as the new current byte. Continue determining if the new current byte meets condition two until all bytes are classified as valid data packets or discarded. If not, discard the current byte and use the next byte as the new current byte, continuing to determine if the new current byte meets condition two.
[0009] Condition 2: The starting byte is the first byte of the TCP packet's protocol header, and the bytes following the current byte after the preset header length JudgeBytes do not exceed the range of the byte array recBytes;
[0010] Step 4: Extract the valid data packets from the listBytes set. The data packets whose length matches the preset header length JudgeBytes are taken as the final valid data packets, thus completing the TCP packet transmission.
[0011] Furthermore, the preset message header includes several bytes, each byte or more of which together constitute a meaning, which is customizable.
[0012] Furthermore, the default message header is set to {0x42, 0x4C, 0x03, 0x00, 0x03}, which contains 5 bytes. 0x42 and 0x4C together form the protocol header of the TCP message, the third byte 0x03 indicates the configuration length, 0x00 indicates the major category of the device type, and the fifth byte 0x03 indicates the minor category of the device type.
[0013] A processing terminal, comprising:
[0014] Memory, used to store program instructions;
[0015] A processor is configured to run the program instructions to perform the steps of the TCP packet transmission method for avoiding packet fragmentation.
[0016] The beneficial effects of this invention are as follows: This invention separates (i.e. slices) TCP packets by customizing the packet header of a fixed-length TCP packet. This can quickly and accurately identify TCP packets and effectively determine the integrity of data packets. Only when the packet length and data fields are consistent will the data packet be considered complete, thereby improving the reliability of TCP packet processing and avoiding packet merging. Attached Figure Description
[0017] Figure 1This is a schematic diagram of the process of the present invention;
[0018] Figure 2 This is a schematic diagram of the processing terminal. Detailed Implementation
[0019] The present invention will now be further described with reference to the accompanying drawings and specific embodiments:
[0020] like Figure 1 As shown, a TCP packet transmission method to avoid packet fragmentation includes the following steps:
[0021] Step 1: Receive the byte array recBytes containing TCP packets.
[0022] Step 2: Determine if the currently received byte array recBytes satisfies condition 1. If yes, return the listBytes collection and end the processing. The listBytes collection is initially empty. If not, continue to step 3. The listBytes collection stores valid data packets in the TCP segment. Valid data packets refer to the data portion remaining after removing the header, checksum, etc., which is the data to be transmitted.
[0023] Condition 1: The byte array recBytes is empty and its length is less than the preset message header length JudgeBytes.
[0024] The preset header length, JudgeBytes, is the predefined length of the TCP header. In this embodiment, the preset header length, JudgeBytes, is set to 5 bytes. The preset header also includes a composition format, which includes custom bytes representing the protocol header and other bytes with specific meanings.
[0025] For example, the default message header is set to {0x42, 0x4C, 0x03, 0x00, 0x03}, which contains 5 bytes. Each byte or multiple bytes together form a meaning, which can be customized. For example, 0x42 and 0x4C together form the protocol header of the TCP message, the third byte 0x03 indicates the configuration length, 0x00 indicates the major category of the device type, and the fifth byte 0x03 indicates the minor category of the device type.
[0026] Step 3: Iterate through each byte in the byte array recBytes. Starting from the first byte, determine if the current byte meets condition two. If it does, combine all bytes from the current byte to the byte shifted forward by a preset byte length to form a valid data packet, and store the valid data packet in the listBytes set. The byte shifted forward by the preset byte length from the current byte is then used as the new current byte. Continue determining if the new current byte meets condition two until all bytes are classified as valid data packets or discarded. If not, discard the current byte and use the next byte as the new current byte, continuing to determine if the new current byte meets condition two.
[0027] Condition 2: The starting byte is the first byte of the TCP header, and the bytes following the current byte after the preset header length JudgeBytes do not exceed the range of the byte array recBytes.
[0028] Condition two is to determine whether the starting byte of the received byte array recBytes is the first byte of the protocol header of the predefined message header.
[0029] The phrase "the number of bytes after the current byte, following the preset header length JudgeBytes, does not exceed the range of the byte array recBytes" means that the number of remaining bytes after the current byte, following the length JudgeBytes, does not exceed the number of bytes in the received byte array recBytes.
[0030] Step 4: Extract the valid data packets from the listBytes set. The data packets whose length matches the preset header length JudgeBytes are taken as the final valid data packets, thus completing the TCP packet transmission.
[0031] This invention separates (i.e. slices) TCP packets by customizing the packet header of a fixed-length TCP packet. This allows for quick and accurate identification of TCP packets and effective judgment of packet integrity. Only when the packet length and data fields match will the packet be considered complete, thereby improving the reliability of TCP packet processing.
[0032] like Figure 2 As shown, the present invention also provides a processing terminal 100, which includes:
[0033] Memory 101 is used to store program instructions;
[0034] Processor 102 is configured to run the program instructions to perform the steps of the TCP packet transmission method for avoiding packet fragmentation.
[0035] The embodiments disclosed in this specification are merely illustrative of one aspect of the invention, and the scope of protection of the invention is not limited to these embodiments. Any other functionally equivalent embodiments fall within the scope of protection of the invention. Those skilled in the art can make various other corresponding changes and modifications based on the technical solutions and concepts described above, and all such changes and modifications should fall within the scope of protection of the claims of this invention.
Claims
1. A TCP packet transmission method to avoid packet fragmentation, characterized in that, Includes the following steps: Step 1: Receive the byte array recBytes containing TCP packets; Step 2: Determine if the currently received byte array recBytes satisfies condition 1. If yes, return the listBytes collection and end the processing. The listBytes collection is initially empty. If not, continue to step 3. The listBytes collection is used to store valid data packets in the TCP segment. Condition 1: The byte array recBytes is empty and its length is less than the preset message header length JudgeBytes; Step 3: Iterate through each byte in the byte array recBytes. Starting from the first byte, determine if the current byte meets condition two. If it does, combine all bytes from the current byte to the byte shifted forward by a preset byte length to form a valid data packet, and store the valid data packet in the listBytes set. Then, use the byte shifted forward by the preset byte length as the new current byte. Continue determining if the new current byte meets condition two until all bytes are classified as valid data packets or discarded. If not, discard the current byte and use the next byte as the new current byte, continuing to determine if the new current byte meets condition two. Condition 2: The starting byte is the first byte of the TCP packet's protocol header, and the bytes following the current byte after the preset header length JudgeBytes do not exceed the range of the byte array recBytes; Step 4: Extract the valid data packets from the listBytes set. The data packets whose length matches the preset header length JudgeBytes are taken as the final valid data packets, thus completing the TCP packet transmission. The default message header includes several bytes, each byte or more of which together constitute a meaning, which is customizable. The default message header is set to {0x42,0x4C,0x03,0x00,0x03}, which contains 5 bytes. 0x42 and 0x4C together form the protocol header of the TCP message. The third byte 0x03 indicates the configuration length, 0x00 indicates the major category of the device type, and the fifth byte 0x03 indicates the minor category of the device type.
2. A processing terminal, characterized in that, It includes: Memory, used to store program instructions; A processor is configured to run the program instructions to perform the steps of the TCP packet transmission method for avoiding packet fragmentation as described in claim 1.