Search

CN-116668562-B - TCP message transmission method capable of avoiding sticking packets and processing terminal

CN116668562BCN 116668562 BCN116668562 BCN 116668562BCN-116668562-B

Abstract

The invention discloses a TCP message transmission method for avoiding sticky packets, which comprises the steps of 1, receiving a byte array comprising a TCP message, 2, judging whether the currently received byte array meets the conditions, returning to a set if the currently received byte array meets the conditions, ending processing, and continuously executing 3 if the currently received byte array is not empty, traversing each byte in the byte array, starting from the first byte, judging whether the current byte meets the conditions II, if the currently received byte meets the conditions, moving all bytes between the current byte and the current byte backwards by a preset byte length to form an effective data packet, and storing the effective data packet into the set until all bytes are divided into the effective data packet or are discarded. If not, discarding the current byte, and 4, extracting the effective data packet in the set, and taking the data packet with the length consistent with the length of the preset message header as the final effective data packet. The invention improves the reliability of TCP message processing and avoids sticking packets.

Inventors

  • XIA XIN
  • ZHANG CHANGHUA
  • ZHAO DINGJIN

Assignees

  • 广东保伦电子股份有限公司

Dates

Publication Date
20260512
Application Date
20230625

Claims (2)

  1. 1. The TCP message transmission method for avoiding sticking the package is characterized by comprising the following steps: step 1, receiving byte arrays recBytes comprising TCP messages; Step 2, judging whether the currently received byte array recBytes meets the first condition, if yes, returning to the listBytes set, ending the processing, and if no, continuing to execute step 3, wherein the listBytes set is used for storing valid data packets in the TCP message, The first condition is that byte array recBytes is empty and the length is smaller than the length JudgeBytes of the preset message header; Step 3, traversing each byte in the byte array recBytes, starting from the first byte, judging whether the current byte meets the second condition, if so, forming an effective data packet by moving all bytes between the current byte and the current byte backwards by a preset byte length, storing the effective data packet into the listBytes set, taking the byte after moving the preset byte length from the current byte as a new current byte, continuously judging whether the new current byte meets the second condition until all the bytes are divided into the effective data packet or are discarded, if not, discarding the current byte, taking the next byte as the new current byte, continuously judging whether the new current byte meets the second condition, The second condition is that the initial byte is the first byte of the protocol header of the TCP message, and the byte after passing through the length JudgeBytes of the preset message header from the current byte does not exceed the range of the byte array recBytes; step 4, extracting effective data packets in listBytes sets, and taking the data packets with the lengths consistent with the length JudgeBytes of the preset message header as final effective data packets, thereby completing TCP message transmission; the preset message header comprises a plurality of self-bodies, and each byte or a plurality of bytes jointly form a meaning which is self-definition; The preset message header is set to {0x42,0x4C,0x03,0x00,0x03}, and comprises 5 bytes, wherein 0x42 and 0x4C together form a protocol header of the TCP message, the third byte 0x03 represents a configuration length, 0x00 represents a device type major class, and the fifth byte 0x03 represents a device type minor class.
  2. 2. A processing terminal, characterized in that it comprises: a memory for storing program instructions; a processor for executing the program instructions to perform the steps of the method for avoiding sticky packets according to claim 1.

Description

TCP message transmission method capable of avoiding sticking packets and processing terminal Technical Field The invention relates to the technical field of TCP message processing, in particular to a TCP message transmission method and a processing terminal for avoiding sticking packets. Background In computer network communications, the TCP protocol is a reliable, connection-oriented transport layer protocol that is used primarily for the transmission of data between different computers. In the TCP communication process, the message is a basic data transmission unit, the length of the message may not be fixed, and the receiving end needs to separate a plurality of data packets from the byte array after receiving the TCP message. However, if the data packet is directly separated without the processed TCP packet, a packet sticking condition often occurs, so that data transmission errors occur. In addition, in some existing TCP packet processing technologies, it is often circulated to separate the packets by traversing whether each byte in the received TCP packet meets a specific condition, and this method can avoid the packet sticking condition to a certain extent, but the processing efficiency is low and the packet loss easily occurs. Therefore, a TCP packet processing technology for avoiding sticking packets is required, which has high processing efficiency and is not easy to cause packet loss. Disclosure of Invention Aiming at the defects of the prior art, the invention aims to provide a TCP message transmission method and a processing terminal for avoiding sticking, which can solve the problems described in the background art. The technical scheme for realizing the aim of the invention is that the TCP message transmission method for avoiding sticking the package comprises the following steps: step 1, receiving byte arrays recBytes comprising TCP messages; Step 2, judging whether the currently received byte array recBytes meets the first condition, if yes, returning to the listBytes set, ending the processing, and if no, continuing to execute step 3, wherein the listBytes set is used for storing valid data packets in the TCP message, The first condition is that byte array recBytes is empty and the length is smaller than the length JudgeBytes of the preset message header; Step 3, traversing each byte in the byte array recBytes, starting from the first byte, judging whether the current byte meets the second condition, if so, forming an effective data packet by moving all bytes between the current byte and the current byte backwards by a preset byte length, storing the effective data packet into the listBytes set, taking the byte after moving the preset byte length from the current byte as a new current byte, continuously judging whether the new current byte meets the second condition until all the bytes are divided into the effective data packet or are discarded, if not, discarding the current byte, taking the next byte as the new current byte, continuously judging whether the new current byte meets the second condition, The second condition is that the initial byte is the first byte of the protocol header of the TCP message, and the byte after passing through the length JudgeBytes of the preset message header from the current byte does not exceed the range of the byte array recBytes; and 4, extracting the effective data packets in the listBytes sets, and taking the data packets with the lengths consistent with the length JudgeBytes of the preset message header as final effective data packets, thereby completing TCP message transmission. Further, the preset message header includes a plurality of self-bodies, and each byte or a plurality of bytes together form a meaning, and the meaning is self-definition. Further, the preset message header is set to {0x42,0x4C,0x03,0x00,0x03}, and includes 5 bytes, where 0x42 and 0x4C together form a protocol header of the TCP message, the third byte 0x03 represents a configuration length, 0x00 represents a device type major class, and the fifth byte 0x03 represents a device type minor class. A processing terminal, comprising: a memory for storing program instructions; And the processor is used for running the program instructions to execute the steps of the TCP message transmission method for avoiding sticking. The invention has the beneficial effects that the TCP message is separated (namely sliced) by the message head of the TCP message with the self-defined fixed length, the TCP message can be rapidly and accurately identified, the integrity of the data packet can be effectively judged, and the data packet can be judged to be complete only under the condition that the length of the data packet and the data field are identical, thereby improving the reliability of TCP message processing and avoiding sticking the data packet. Drawings FIG. 1 is a schematic flow chart of the present invention; fig. 2 is a schematic diagram of a processing terminal. Detailed Description The