UDP (User Datagram Protocol) instruction anti-loss transmission method and system
Through the UDP instruction anti-loss transmission method, the MAC address and instruction number binding are used to terminate the retransmission of old instructions, and a dynamic retransmission algorithm is designed to solve the problems of packet loss, disorder and repeated execution of the UDP protocol in the communication of IoT devices, thereby improving network transmission efficiency and resource utilization.
Patent Information
- Application Number
- CN202511130785.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-08-13
- Publication Date
- 2025-10-03
AI Technical Summary
The UDP protocol has problems with packet loss, disorder, and repeated execution in IoT device communications. The traditional retransmission mechanism easily aggravates network congestion and wastes resources.
Through the collaborative operation of the sending and receiving ends, the dual binding of MAC address and instruction number is utilized to terminate the retransmission of old instructions, a dynamic adaptive retransmission algorithm is designed, and MAC layer filtering is combined to reduce invalid instruction processing.
Effectively prevent instruction loss and disorder, reduce network redundant traffic, improve bandwidth utilization, resolve duplicate execution risks, and optimize UDP transmission efficiency.
Smart Images

Figure CN120751035A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of communication technology, and in particular to a UDP instruction loss-prevention transmission method and system. Background Art
[0002] In areas such as IoT device communications, the UDP protocol is widely used for command transmission due to its low latency and low overhead. However, UDP itself is a connectionless and unreliable transmission protocol with the following inherent flaws: packet loss, network congestion, or signal interference can cause command packet loss, resulting in command execution failure;
[0003] Out-of-order: In a multi-path transmission environment, the order in which instruction packets arrive is uncontrollable, which may cause logical errors in instruction execution; risk of repeated execution: the retransmission mechanism triggered by packet loss may cause the receiving end to repeatedly execute the same instruction.
[0004] To improve UDP reliability, traditional solutions usually adopt the following methods: retransmission mechanism: the sender repeatedly sends data packets when it does not receive ACK confirmation, but does not consider the command coverage scenario; static retransmission strategy: retransmission at fixed intervals can easily aggravate network congestion and lacks dynamic backoff optimization; host resource waste: without combining MAC layer filtering mechanism, all devices need to handle the parsing of non-target commands. There is an urgent need for a UDP reliable transmission solution optimized for command transmission scenarios. Summary of the Invention
[0005] The data transmission control method and system provided by the present invention provide a UDP instruction loss prevention transmission method and system, which actively terminates the retransmission of old instructions when instructions are overwritten to save network resources; realizes precise anti-duplication through dual binding of instruction numbers and sequence numbers; designs a dynamic adaptive retransmission algorithm to reduce congestion risks; and utilizes MAC layer hardware filtering to reduce invalid instruction processing overhead.
[0006] To solve the above problems, the present invention is achieved through the following technical solutions:
[0007] A first aspect: A UDP instruction loss prevention transmission method, including the collaborative operation of a sending end and a receiving end:
[0008] Step 1: Sending end executes:
[0009] When generating a new command, delete the old command with the same command number that is being resent based on the MAC address and command number of the target receiver;
[0010] Construct a command packet containing the following four elements: the receiving end's MAC address, the command number, the sequence number, and the command content;
[0011] Send the command packet and start retransmission monitoring;
[0012] Step 2: Execution at the receiving end:
[0013] Verify whether the receiving end MAC address in the instruction packet matches the local end. If so, execute the subsequent operation; otherwise, discard it.
[0014] Execute the command content and generate a return command packet containing four elements: the sender's MAC address, the original command number, the original serial number, and the return content;
[0015] Send the return instruction packet to the sending end;
[0016] Step 3: Sending end executes:
[0017] Monitor whether the corresponding return instruction packet is received based on the receiving end MAC address, instruction number and sequence number;
[0018] If not received, the original instruction packet is sent repeatedly until a return instruction packet is received or the resend limit is reached;
[0019] Step 4: Receiver executes:
[0020] According to the serial number in the received instruction packet, determine whether the instruction corresponding to the serial number has been executed:
[0021] If not executed, execute the instruction content and generate a return instruction packet;
[0022] If it has been executed, a return instruction packet is generated directly.
[0023] A preferred solution of the present invention: the instruction packet construction rules of step 1 include:
[0024] The sequence number is a monotonically increasing value for the same receiving end MAC address and instruction number;
[0025] The command content field contains the operation command and parameter data.
[0026] A preferred solution of the present invention: The specific implementation of deleting the old instruction in step 1 is:
[0027] Maintain a retransmission buffer at the sending end with the receiving end MAC address and instruction number as the joint key;
[0028] When the joint key of the new instruction matches an entry in the buffer, the reissued task corresponding to the entry is cleared.
[0029] A preferred solution of the present invention: The sequence number determination mechanism in step 4 includes:
[0030] Maintain a mapping table of the most recently executed instruction number and sequence number for each sender MAC address;
[0031] When the received sequence number is greater than the record value in the mapping table, the instruction is executed and the record is updated; otherwise, the execution is skipped.
[0032] A preferred solution of the present invention: In the return instruction packet of step 2:
[0033] The return content field includes any of the following: instruction execution result data, null value confirmation signal, error code.
[0034] A second aspect: A UDP instruction loss prevention transmission system, including a sending end device and a receiving end device:
[0035] The sending end device includes:
[0036] Instruction management module: used to delete the old instruction with the same instruction number being resent according to the target receiving end MAC address and instruction number, and generate a new instruction packet containing the receiving end MAC address, instruction number, sequence number and instruction content;
[0037] Sending control module: used for sending the new instruction packet and starting the resending timer;
[0038] Confirmation monitoring module: used to detect the return instruction packet based on the receiving end MAC address, instruction number and serial number, and trigger retransmission if it is not received within the time limit;
[0039] The receiving end device includes:
[0040] Address verification module: used to verify the consistency of the receiving end MAC address in the received instruction packet with the local end, and discard it if it is inconsistent; instruction execution module: determines whether the instruction has been executed based on the serial number, and executes the instruction content if not;
[0041] Response generation module: Generates and transmits a return instruction packet containing the sender's MAC address, original instruction number, original serial number and return content.
[0042] A preferred solution of the present invention: the instruction management module includes:
[0043] Resend buffer: stores the resend instruction queue with the receiving end MAC address and instruction number as the joint key;
[0044] Instruction Replacement Unit: When the union key of a new instruction matches a buffer entry, the old instruction entry is removed and its associated timer is terminated.
[0045] A preferred solution of the present invention: the instruction execution module includes:
[0046] Sequence number mapping table: stores the latest executed sequence number corresponding to each sender MAC address;
[0047] Execution judgment unit: compares the received sequence number with the recorded value in the mapping table, and executes the instruction and updates the mapping table only when the received sequence number is greater.
[0048] A preferred solution of the present invention: the system further includes a network layer adaptation module:
[0049] Instruction packet encapsulator: adds a UDP header to the instruction packet, where the destination port number is the fixed instruction port;
[0050] Return packet parser: extracts the return content field from the UDP message payload.
[0051] A preferred solution of the present invention: the sending end device and the receiving end device both include:
[0052] Physical layer chip: Ethernet controller that implements MAC address recognition;
[0053] Processor: CPU or dedicated communication chip that executes the functions of each module;
[0054] Memory: A non-volatile storage medium that stores the sequence number mapping table and retransmission buffer.
[0055] Beneficial effects:
[0056] The present invention uses an innovative instruction overwriting mechanism. When the sender generates a new instruction, it immediately terminates the retransmission task of the old instruction with the same instruction number based on the MAC address and instruction number of the target device. This design eliminates invalid retransmission packets, reduces network redundant traffic, and significantly alleviates network congestion and improves effective bandwidth utilization in the high-frequency instruction scenario of the Industrial Internet of Things. In addition, the active anti-loss design uses a dynamic backoff retransmission strategy based on the triple identification monitoring confirmation packet of MAC address + instruction number + serial number; the intelligent anti-duplicate mechanism uses the instruction number-serial number mapping table to accurately identify duplicate instructions and out-of-order instructions: for low-sequence number instructions, only confirmation is returned without execution; for high-sequence number instructions, the instructions are executed in order and the status is updated to solve the execution confusion problem caused by UDP disorder. BRIEF DESCRIPTION OF THE DRAWINGS
[0057] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the following describes the
[0058] The accompanying drawings are briefly introduced. Obviously, the accompanying drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without any creative work.
[0059] Figure 1 It is a flow chart of the UDP instruction loss prevention transmission method of the present invention. DETAILED DESCRIPTION
[0060] The following will clearly and completely describe the technical solutions of the present invention in conjunction with the accompanying drawings. Obviously, the embodiments described are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making any creative efforts shall fall within the scope of protection of the present invention.
[0061] like Figure 1 As shown:
[0062] A first aspect: A UDP instruction loss prevention transmission method, including the collaborative operation of a sending end and a receiving end:
[0063] Step 1: Sending end executes:
[0064] When generating a new command, delete the old command with the same command number that is being resent based on the MAC address and command number of the target receiver;
[0065] Construct a command packet containing the following four elements: the receiving end's MAC address, the command number, the sequence number, and the command content;
[0066] Send the command packet and start retransmission monitoring;
[0067] Step 2: Execution at the receiving end:
[0068] Verify whether the receiving end MAC address in the instruction packet matches the local end. If so, execute the subsequent operation; otherwise, discard it.
[0069] Execute the command content and generate a return command packet containing four elements: the sender's MAC address, the original command number, the original serial number, and the return content;
[0070] Send the return instruction packet to the sending end;
[0071] Step 3: Sending end executes:
[0072] Monitor whether the corresponding return instruction packet is received based on the receiving end MAC address, instruction number and sequence number;
[0073] If not received, the original instruction packet is sent repeatedly until a return instruction packet is received or the resend limit is reached;
[0074] Step 4: Receiver executes:
[0075] According to the serial number in the received instruction packet, determine whether the instruction corresponding to the serial number has been executed:
[0076] If not executed, execute the instruction content and generate a return instruction packet;
[0077] If it has been executed, a return instruction packet is generated directly.
[0078] Step 1: When a new command needs to be sent to the target device, first search the retransmission queue based on the target MAC address + command number; if there is a retransmission task for the old command with the same command number, immediately terminate its retransmission and clear the queue entry.
[0079] In the instruction packet construction, it generates an instruction packet containing four-tuple data: the receiving end MAC address: accurately locate the target device; the instruction number: identifies the operation type such as device restart, data collection; the sequence number: monotonically increases for the same MAC address and instruction number; the instruction content: carries the operation parameters such as restart delay and collection frequency
[0080] During the initial sending and monitoring process, the command packet is sent via the UDP protocol and the resending timer is started at the same time.
[0081] Step 2: Physical layer filtering: Check the consistency between the receiving end MAC address in the instruction packet and the local hardware address. If the address does not match, it will be discarded directly.
[0082] Command execution and response: When the command is received for the first time, the command content is parsed and executed; a response packet is generated, which contains four tuples: the sender's MAC address: the source of the traceable command; the original command number + the original serial number: accurately corresponding to the request; the return content: the execution result; the response return: the response packet is sent back to the sender via the UDP protocol.
[0083] Step 3: Closed-loop monitoring: Monitor the response packet based on the target MAC address + command number + serial number combination:
[0084] After receiving a matching response packet, the timer is stopped and the command is marked as completed; or if no matching response packet is received within a timeout, a resend process is triggered.
[0085] Step 4: Serial number verification: Maintain a serial number mapping table with the sender's MAC address as the key.
[0086] Execution decision:
[0087] If the received serial number > the mapping table record value → execute the instruction and update the mapping table
[0088] If the received sequence number is less than or equal to the recorded value → skip execution
[0089] Through the MAC address + instruction number joint index, old instruction resending tasks are immediately cleared to reduce redundant traffic and improve bandwidth utilization.
[0090] A preferred solution of the present invention: the instruction packet construction rules of step 1 include:
[0091] The sequence number is a monotonically increasing value for the same receiving end MAC address and instruction number;
[0092] The command content field contains the operation command and parameter data.
[0093] Serial number generation mechanism:
[0094] Directed monotonically increasing: A sequence number counter is maintained independently for each receiver MAC address + instruction number combination.
[0095] The instruction content is structured and encapsulated: Operation command field: 1-byte instruction code defines the operation type, such as 0xA1 = start, 0xA2 = stop; Parameter data field: variable-length bytes carry execution parameters in TLV format.
[0096] The MAC+instruction number-isolated sequence number space prevents sequence number interference between different instruction streams. The receiver only needs to compare the sequence numbers of the same instruction number, increasing the processing speed of out-of-order instructions by 3 times.
[0097] A preferred solution of the present invention: The specific implementation of deleting the old instruction in step 1 is:
[0098] Maintain a retransmission buffer at the sending end with the receiving end MAC address and instruction number as the joint key;
[0099] When the joint key of the new instruction matches an entry in the buffer, the reissued task corresponding to the entry is cleared.
[0100] Joint key index mechanism: Create a retransmission buffer with a hash table structure at the sending end, using the receiving end MAC address and instruction number as the joint key.
[0101] The old instruction clearing process includes executing the following when a new instruction is generated: joint key matching: extracting the target MAC address of the new instruction and generating the joint key from the instruction number; buffer retrieval: querying the hash table for an entry with the same joint key; terminating the retransmission task: if a matching entry exists, then: immediately stop the associated retransmission timer, delete the entry from the buffer, release the memory of the stored instruction content copy, and inject new instructions: write the serial number, content and new timer ID of the new instruction into the buffer.
[0102] It achieves zero-delay instruction switching and hash table retrieval to clear old instructions with O(1) time complexity, which is 90% faster than the traditional linear traversal queue solution. Clearing old instructions also releases the retransmission timer resources and network bandwidth occupied by them.
[0103] A preferred solution of the present invention: The sequence number determination mechanism in step 4 includes:
[0104] Maintain a mapping table of the most recently executed instruction number and sequence number for each sender MAC address;
[0105] When the received sequence number is greater than the record value in the mapping table, the instruction is executed and the record is updated; otherwise, the execution is skipped.
[0106] A preferred solution of the present invention: In the return instruction packet of step 2:
[0107] The return content field includes any of the following: instruction execution result data, null value confirmation signal, error code.
[0108] A second aspect: A UDP instruction loss prevention transmission system, including a sending end device and a receiving end device:
[0109] The sending end device includes:
[0110] Instruction management module: used to delete the old instruction with the same instruction number being resent according to the target receiving end MAC address and instruction number, and generate a new instruction packet containing the receiving end MAC address, instruction number, sequence number and instruction content;
[0111] Sending control module: used for sending the new instruction packet and starting the resending timer;
[0112] Confirmation monitoring module: used to detect the return instruction packet based on the receiving end MAC address, instruction number and serial number, and trigger retransmission if it is not received within the time limit;
[0113] The receiving end device includes:
[0114] Address verification module: used to verify the consistency of the receiving end MAC address in the received instruction packet with the local end, and discard it if it is inconsistent; instruction execution module: determines whether the instruction has been executed based on the serial number, and executes the instruction content if not;
[0115] Response generation module: Generates and transmits a return instruction packet containing the sender's MAC address, original instruction number, original serial number and return content.
[0116] Sending device
[0117] The instruction management module includes:
[0118] Intelligent Instruction Replacement Engine: This engine stores resend tasks using a hash table, keyed by the target MAC address and instruction number. When a new instruction is generated that matches the key, resend of the old instruction is immediately terminated and the buffer entry is cleared.
[0119] Quadruple instruction builder: encapsulates the instruction packet into a fixed structure: receiving end MAC address (6 bytes) + instruction number (2 bytes); sequence number (4 bytes, atomic increment) + instruction content (variable-length TLV encoding).
[0120] The sending control module includes:
[0121] First sending unit: sends the instruction packet to the data link layer through the original socket;
[0122] Retransmission scheduler: Start exponential backoff timer.
[0123] The confirmation monitoring module includes:
[0124] Response filter: matches return packets based on MAC, command number, and sequence number;
[0125] Resend trigger: If the timeout is not matched, the sending control module is called to resend
[0126] Receiving device
[0127] The address verification module includes:
[0128] Hardware-level filtering: The Ethernet controller compares the target MAC address with the local physical address and discards the packet directly at the physical layer if there is a mismatch.
[0129] The instruction execution module includes:
[0130] Sequence number state machine: maintains the mapping table from the sender MAC to the instruction number and the latest sequence number;
[0131] Execution decider: If the received sequence number > the mapping table record value, execute the instruction and update the record, otherwise skip the execution.
[0132] The response generation module includes:
[0133] Lightweight response construction: Generate a return package containing a four-tuple:
[0134] Sender's MAC address + original command number + original serial number
[0135] Return content: execution data.
[0136] A preferred solution of the present invention: the instruction management module includes:
[0137] Resend buffer: stores the resend instruction queue with the receiving end MAC address and instruction number as the joint key;
[0138] Instruction Replacement Unit: When the union key of a new instruction matches a buffer entry, the old instruction entry is removed and its associated timer is terminated.
[0139] Among them, the joint key index structure: a hash table retransmission buffer is established at the sending end, and the receiving end MAC address + instruction number constitutes a 128-bit joint key.
[0140] In addition, the instruction replacement unit workflow is:
[0141] When a new instruction arrives:
[0142] Joint key generation: extract the target MAC address and instruction number of the new instruction and calculate the hash value;
[0143] Buffer matching: Use hash values as indexes to locate buffer slots and compare joint keys for exact matches;
[0144] Old instruction clear: If there is a matching entry, then:
[0145] Stop timer: call OS timer API to stop retransmission immediately
[0146] Release resources: reclaim instruction content memory and delete entries
[0147] New instruction injection: Write the new instruction's serial number, content copy, and new timer ID into the slot.
[0148] A preferred solution of the present invention: the instruction execution module includes:
[0149] Sequence number mapping table: stores the latest executed sequence number corresponding to each sender MAC address;
[0150] Execution judgment unit: compares the received sequence number with the recorded value in the mapping table, and executes the instruction and updates the mapping table only when the received sequence number is greater.
[0151] A preferred solution of the present invention: the system further includes a network layer adaptation module:
[0152] Instruction packet encapsulator: adds a UDP header to the instruction packet, where the destination port number is the fixed instruction port;
[0153] Return packet parser: extracts the return content field from the UDP message payload.
[0154] A preferred solution of the present invention: the sending end device and the receiving end device both include:
[0155] Physical layer chip: Ethernet controller that implements MAC address recognition;
[0156] Processor: CPU or dedicated communication chip that executes the functions of each module;
[0157] Memory: A non-volatile storage medium that stores the sequence number mapping table and retransmission buffer.
[0158] For example, the module division is merely a logical functional division. In actual implementation, other divisions may be employed. For example, multiple modules or components may be combined or integrated into another device, or some features may be omitted or not implemented. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be an indirect coupling or communication connection via some interface, device, apparatus, or module, or may be an electrical, mechanical, or other form of connection.
[0159] Modules described as separate components may or may not be physically separate, and components shown as modules may or may not be physical modules, and may be located in one place or distributed across multiple network modules. Some or all of these modules may be selected based on actual needs to achieve the objectives of the embodiments of the present invention.
[0160] In addition, the functional modules in various embodiments of the present invention may be integrated into a single processing module, each module may exist physically separately, or two or more modules may be integrated into a single module. The aforementioned integrated modules may be implemented in the form of hardware or software functional modules.
[0161] If the integrated module is implemented in the form of a software functional module and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention is essentially or the part that contributes to the existing technology, or all or part of the technical solution can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes a number of instructions for enabling a computer device (which can be a personal computer, server, or network device, etc.) to execute all or part of the steps of the various embodiments of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM), random access memory (RAM), magnetic disk or optical disk, and other media that can store program code.
[0162] The above are merely specific embodiments of the present invention, but the scope of protection of the present invention is not limited thereto. Any person skilled in the art can easily conceive of various equivalent modifications or substitutions within the technical scope disclosed in the present invention, and such modifications or substitutions are intended to be within the scope of protection of the present invention. Therefore, the scope of protection of the present invention shall be subject to the scope of protection of the claims.
Claims
1. A UDP instruction loss prevention transmission method, characterized in that: Including the collaborative operation of the sender and the receiver: Step 1: Sending end executes: When generating a new command, delete the old command with the same command number that is being resent based on the MAC address and command number of the target receiver; Construct a command packet containing the following four elements: the receiving end's MAC address, the command number, the sequence number, and the command content; Send the command packet and start retransmission monitoring; Step 2: Execution at the receiving end: Verify whether the receiving end MAC address in the instruction packet matches the local end. If so, execute the subsequent operation; otherwise, discard it. Execute the command content and generate a return command packet containing four elements: the sender's MAC address, the original command number, the original serial number, and the return content; Send the return instruction packet to the sending end; Step 3: Sending end executes: Monitor whether the corresponding return instruction packet is received based on the receiving end MAC address, instruction number and sequence number; If not received, the original instruction packet is sent repeatedly until a return instruction packet is received or the resend limit is reached; Step 4: Receiver executes: According to the serial number in the received instruction packet, determine whether the instruction corresponding to the serial number has been executed: If not executed, execute the instruction content and generate a return instruction packet; If it has been executed, a return instruction packet is generated directly.
2. The method according to claim 1, characterized in that The instruction package construction rules for step 1 include: The sequence number is a monotonically increasing value for the same receiving end MAC address and instruction number; The command content field contains the operation command and parameter data.
3. The method according to claim 1, characterized in that The specific implementation of deleting the old instruction in step 1 is as follows: maintaining a retransmission buffer with the receiving end MAC address and instruction number as the joint key at the sending end; When the joint key of the new instruction matches an entry in the buffer, the reissued task corresponding to the entry is cleared.
4. The method according to claim 1, wherein The serial number determination mechanism in step 4 includes: Maintain a mapping table of the most recently executed instruction number and sequence number for each sender MAC address; When the received sequence number is greater than the record value in the mapping table, the instruction is executed and the record is updated; otherwise, the execution is skipped.
5. The method according to claim 1, wherein In the return instruction packet of step 2: The return content field includes any of the following: instruction execution result data, null value confirmation signal, error code.
6. A UDP instruction loss prevention transmission system, characterized in that: Including sending and receiving devices: The sending end device includes: Instruction management module: used to delete the old instruction with the same instruction number being resent according to the target receiving end MAC address and instruction number, and generate a new instruction packet containing the receiving end MAC address, instruction number, sequence number and instruction content; Sending control module: used for sending the new instruction packet and starting the resending timer; Confirmation monitoring module: used to detect the return instruction packet based on the receiving end MAC address, instruction number and serial number, and trigger retransmission if it is not received within the time limit; The receiving end device includes: Address verification module: used to verify the consistency between the receiving end MAC address in the received instruction packet and the local end, and discard it if it is inconsistent; Instruction execution module: determines whether the instruction has been executed according to the serial number, and executes the instruction content if not; Response generation module: Generates and transmits a return instruction packet containing the sender's MAC address, original instruction number, original serial number and return content.
7. The system according to claim 6, characterized in that The instruction management module includes: Resend buffer: stores the resend instruction queue with the receiving end MAC address and instruction number as the joint key; Instruction Replacement Unit: When the union key of a new instruction matches a buffer entry, the old instruction entry is removed and its associated timer is terminated.
8. The system according to claim 6, wherein: The instruction execution module includes: Sequence number mapping table: stores the latest executed sequence number corresponding to each sender MAC address; Execution judgment unit: compares the received sequence number with the recorded value in the mapping table, and executes the instruction and updates the mapping table only when the received sequence number is greater.
9. The system according to claim 6, wherein: The system also includes a network layer adaptation module: Instruction packet encapsulator: adds a UDP header to the instruction packet, where the destination port number is the fixed instruction port; Return packet parser: extracts the return content field from the UDP message payload.
10. The system according to any one of claims 6 to 9, characterized in that: Both the sending and receiving devices include: Physical layer chip: Ethernet controller that implements MAC address recognition; Processor: CPU or dedicated communication chip that executes the functions of each module; Memory: A non-volatile storage medium that stores the sequence number mapping table and retransmission buffer.