A method and apparatus for parsing tcp data, and a storage medium

By creating port configuration parameters on the visual configuration page of the IoT access platform, port reuse and decoding logic decoupling are supported, which solves the problems of insufficient port resources and coupled decoding logic of IoT device access platforms, and realizes efficient TCP message parsing and management.

CN119676101BActive Publication Date: 2026-01-13GUANGDONG ESHORE TECH
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202311213369.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-09-19
Publication Date
2026-01-13
Estimated Expiration
2043-09-19

AI Technical Summary

Technical Problem

When IoT access platforms are deployed in a customer's private environment, insufficient port resources and severe coupling of decoding logic lead to TCP message parsing errors and omissions.

Method used

By creating port configuration parameters on the visual configuration page, port reuse is supported. The decoding logic is handled by the server of the IoT device access platform, and the business logic is exposed to business developers through the parent class interface, thus decoupling the decoding and business processing logic between multiple protocols.

Benefits of technology

It avoids wasting port resources, provides a unified management interface, reduces the probability of errors caused by coupling decoding and business processing logic, and improves the correctness and efficiency of TCP message parsing.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119676101B_ABST
    Figure CN119676101B_ABST
Patent Text Reader

Abstract

The application provides a TCP data analysis processing method and device and a storage medium. The method comprises the following steps: obtaining configuration parameters of a port of an Internet of Things device access platform, and initializing the configuration parameters; when the port receives TCP streaming data from a terminal device, reading a target protocol field in the TCP streaming data, identifying a target TCP protocol of the TCP streaming data according to the target protocol field and the configuration parameters; analyzing the target TCP protocol to obtain protocol content; determining a target business logic processing class field of the target TCP protocol according to the configuration parameters; and exposing the business processing logic of the protocol content in the form of a parent class interface on the port according to the target business logic processing class field. The application can support multiplexing ports, avoid waste of port resources, and avoid the problem that TCP messages cannot be correctly analyzed, resulting in message omission or message processing error.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of Internet of Things (IoT) technology, and in particular to a method, apparatus, and storage medium for parsing and processing TCP data. Background Technology

[0002] As an IoT device access platform, it is often necessary to connect to various terminal devices from different manufacturers. These terminal devices connect to the IoT device access platform via TCP, and the TCP protocols used by these terminal devices are all custom-defined by the manufacturers, with protocol formats often differing greatly.

[0003] Throughout the access process, when the IoT access platform is deployed in a customer's private environment, there are other applications in the customer's deployment environment. The range of ports that can be exposed to the outside of the IoT access platform is strictly limited. If a single port corresponds to a single TCP protocol, there may be a problem of insufficient port resources for IoT devices to access the platform. In addition, since the decoding logic of multiple TCP protocols is usually written together, if a single port corresponds to multiple TCP protocols, there may be a problem of severe coupling of decoding and processing logic, which may frequently result in the inability to correctly parse TCP messages, leading to message omissions or message processing errors. Summary of the Invention

[0004] This application provides a method, apparatus, and storage medium for parsing and processing TCP data to solve the problems existing in related technologies. The technical solution is as follows:

[0005] In a first aspect, embodiments of this application provide a method for parsing and processing TCP data, including:

[0006] Obtain the configuration parameters of the port of the IoT device access platform, and initialize the configuration parameters. The configuration parameters are created based on the various configuration items on the visual configuration page. The configuration parameters include N TCP protocols corresponding to the port, as well as the protocol field and business logic processing class field of any TCP protocol, where N is an integer greater than or equal to 1.

[0007] When the port receives TCP streaming data from the terminal device, it reads the target protocol field in the TCP streaming data and identifies the target TCP protocol of the TCP streaming data based on the target protocol field and the configuration parameters.

[0008] Parse the target TCP protocol to obtain the protocol content;

[0009] Based on the configuration parameters, determine the target business logic processing class field of the target TCP protocol;

[0010] Based on the target business logic processing class field, the business processing logic of the protocol content is exposed on the port in the form of a parent class interface.

[0011] In one implementation, the protocol fields of any of the TCP protocols include three fields: header, trailer, and length, wherein the target protocol field is the header field;

[0012] Read the target protocol field from the TCP streaming data, and identify the target TCP protocol of the TCP streaming data based on the target protocol field and the configuration parameters, including:

[0013] Read the packet header fields from the TCP streaming data;

[0014] Based on the packet header field and the configuration parameters, the target TCP protocol of the TCP streaming data is identified.

[0015] In one implementation, reading the packet header fields in the TCP streaming data includes:

[0016] Read the first two bytes from the TCP streaming data to obtain the packet header field;

[0017] If less than two bytes are read at the moment, the currently read bytes are buffered, and subsequent bytes are waited for to arrive until the first two bytes of the TCP streaming data are read.

[0018] In one implementation, initializing the configuration parameters includes:

[0019] Load any of the aforementioned TCP protocols;

[0020] For any one of the TCP protocols, generate a decoder instance for that TCP protocol;

[0021] Generate a decoder for any TCP protocol based on any TCP protocol decoder instance.

[0022] In one implementation, parsing the target TCP protocol to obtain the protocol content includes:

[0023] The decoder of the target TCP protocol is invoked to parse the valid complete byte stream data in the target TCP protocol and obtain the protocol content.

[0024] In one implementation, the configuration parameters further include any protocol field conversion result field of the TCP protocol;

[0025] Based on the target business logic processing class field, the business processing logic of the protocol content is exposed on the port in the form of a parent class interface, including:

[0026] Based on the configuration parameters, determine the target protocol field conversion result class field of the target TCP protocol;

[0027] Based on the target protocol field conversion result class field, the protocol content is converted into a protocol field conversion result class instance;

[0028] Generate a business logic processing class instance based on the target business logic processing class field;

[0029] The instance of the protocol field conversion result class is passed to the business logic processing class, thereby exposing the business processing logic of the protocol content on the port in the form of a parent class interface.

[0030] In one implementation, the configuration parameters further include any of the TCP protocol's protocol content verification fields; the method further includes:

[0031] Based on the configuration parameters, determine the target protocol content verification class field of the target TCP protocol;

[0032] Based on the target protocol content verification class field, the general verification processor is invoked to verify the protocol content;

[0033] After the protocol content verification is successful, the target business logic processing class field of the target TCP protocol is determined according to the configuration parameters.

[0034] In one embodiment, the method further includes:

[0035] When any new TCP protocol is added, the configuration parameters are updated in response to the addition of new protocol configuration items, protocol field configuration items, and business logic processing class configuration items on the visual configuration page.

[0036] Secondly, embodiments of this application also provide a TCP data parsing and processing apparatus, including:

[0037] The processing unit is used to obtain the configuration parameters of the port of the IoT device access platform, and initialize the configuration parameters. The configuration parameters are created based on the various configuration items on the visual configuration page. The configuration parameters include N TCP protocols corresponding to the port, as well as the protocol field and business logic processing class field of any TCP protocol, where N is an integer greater than or equal to 1.

[0038] The identification unit is used to read the target protocol field in the TCP streaming data when the port receives TCP streaming data from the terminal device, and identify the target TCP protocol of the TCP streaming data according to the target protocol field and the configuration parameters.

[0039] The parsing unit is used to parse the target TCP protocol to obtain the protocol content; determine the target business logic processing class field of the target TCP protocol according to the configuration parameters; and expose the business processing logic of the protocol content on the port in the form of a parent class interface according to the target business logic processing class field.

[0040] In one implementation, any of the TCP protocol protocol fields includes three fields: header, trailer, and length, wherein the target protocol field is the header field; the identification unit is specifically used for:

[0041] Read the packet header fields from the TCP streaming data;

[0042] Based on the packet header field and the configuration parameters, the target TCP protocol of the TCP streaming data is identified.

[0043] In one embodiment, the identification unit is specifically used for:

[0044] Read the first two bytes from the TCP streaming data to obtain the packet header field;

[0045] If less than two bytes are read at the moment, the currently read bytes are buffered, and subsequent bytes are waited for to arrive until the first two bytes of the TCP streaming data are read.

[0046] In one embodiment, the processing unit is specifically used for:

[0047] Load any of the aforementioned TCP protocols;

[0048] For any one of the TCP protocols, generate a decoder instance for that TCP protocol;

[0049] Generate a decoder for any TCP protocol based on any TCP protocol decoder instance.

[0050] In one implementation, the parsing unit is specifically used for:

[0051] The decoder of the target TCP protocol is invoked to parse the valid complete byte stream data in the target TCP protocol and obtain the protocol content.

[0052] In one implementation, the configuration parameters further include a protocol field conversion result field of any of the TCP protocols; the parsing unit is specifically used for:

[0053] Based on the configuration parameters, determine the target protocol field conversion result class field of the target TCP protocol;

[0054] Based on the target protocol field conversion result class field, the protocol content is converted into a protocol field conversion result class instance;

[0055] Generate a business logic processing class instance based on the target business logic processing class field;

[0056] The instance of the protocol field conversion result class is passed to the business logic processing class, thereby exposing the business processing logic of the protocol content on the port in the form of a parent class interface.

[0057] In one implementation, the configuration parameters further include any of the TCP protocol's protocol content verification fields; the parsing unit is further configured to:

[0058] Based on the configuration parameters, determine the target protocol content verification class field of the target TCP protocol;

[0059] Based on the target protocol content verification class field, the general verification processor is invoked to verify the protocol content;

[0060] After the protocol content verification is successful, the target business logic processing class field of the target TCP protocol is determined according to the configuration parameters.

[0061] In one embodiment, the processing unit is further configured to:

[0062] When any new TCP protocol is added, the configuration parameters are updated in response to the addition of new protocol configuration items, protocol field configuration items, and business logic processing class configuration items on the visual configuration page.

[0063] Thirdly, embodiments of this application also provide a computer device, which includes a memory and a processor. The memory stores instructions that are loaded and executed by the processor to implement the methods in any of the above embodiments. The memory and the processor communicate with each other via an internal connection path.

[0064] Fourthly, embodiments of this application also provide a computer-readable storage medium storing a computer program that, when run on a computer, implements the methods in any of the above-described embodiments.

[0065] The advantages or beneficial effects of the above technical solutions include at least the following:

[0066] This application supports port reuse by creating port configuration parameters on a visual configuration page, avoiding port resource waste. It also provides a unified management interface, allowing business developers or administrators to understand which ports the IoT device access platform currently exposes and which protocols it supports. Furthermore, this configuration parameter can define a programming paradigm: decoding logic is handled by the IoT device access platform's server, while business logic is exposed to specific business developers through a parent class interface. Overall, this decoupling of decoding and business processing logic across multiple protocols reduces the probability of errors caused by mutual interference, thus preventing issues such as incorrect TCP message parsing leading to message omissions or processing errors.

[0067] The above overview is for illustrative purposes only and is not intended to be limiting in any way. In addition to the illustrative aspects, embodiments, and features described above, further aspects, embodiments, and features of this application will become readily apparent from the accompanying drawings and the following detailed description. Attached Figure Description

[0068] In the accompanying drawings, unless otherwise specified, the same reference numerals throughout the various drawings denote the same or similar parts or elements. These drawings are not necessarily drawn to scale. It should be understood that these drawings depict only some embodiments disclosed in this application and should not be construed as limiting the scope of this application.

[0069] Figure 1 A flowchart illustrating a TCP data parsing and processing method provided in this application;

[0070] Figure 2 An example diagram of a visual configuration page provided in this application;

[0071] Figure 3 An example diagram illustrating the server-side decoding and business processing of an IoT device access platform provided in this application;

[0072] Figure 4 Example diagram of a protocol field conversion result class instance provided in this application;

[0073] Figure 5 A structural block diagram of a TCP data parsing and processing device provided in this application;

[0074] Figure 6 A structural block diagram of a computer device provided in this application. Detailed Implementation

[0075] In the following description, only certain exemplary embodiments are briefly described. As those skilled in the art will recognize, the described embodiments can be modified in various ways without departing from the spirit or scope of this application. Therefore, the drawings and description are considered to be exemplary in nature and not restrictive.

[0076] TCP is a streaming protocol, and the server must handle packet fragmentation and incomplete packet issues during decoding. Furthermore, some custom protocols define verification logic to prevent data tampering, which also needs to be handled during decoding. When a single port connects to a single terminal device, the decoding logic is relatively easy to handle; however, when a single port supports multiple terminal devices, the decoding logic becomes heavily coupled, frequently resulting in incorrect TCP message parsing, leading to message omissions or processing errors.

[0077] In related technologies, in single-port, single-protocol scenarios, according to best practice principles, decoding logic and business logic are usually handled separately. In single-port, multi-protocol scenarios, decoding logic (such as protocol identification, protocol content parsing, decoding exception handling, etc.) usually depends on the design and coding capabilities of business developers. Moreover, the decoding logic of multiple protocols is usually written together, forming strong coupling, and the decoding logic is also relatively complex to handle. After decoding, subsequent business processing can also easily form strong coupling. The fundamental reason is that when the capabilities of business developers vary, it is easy to write high-quality program code.

[0078] Figure 1 A flowchart illustrating a TCP data parsing and processing method according to an embodiment of this application is shown. Figure 1 As shown, the method may include the following steps:

[0079] S110. Obtain the configuration parameters of the port of the IoT device access platform and initialize the configuration parameters. The configuration parameters are created based on the various configuration items on the visual configuration page.

[0080] In one implementation, the configuration parameters may include, but are not limited to: N TCP protocols corresponding to the port, and the protocol field and business logic processing class field of any TCP protocol, where N is an integer greater than or equal to 1.

[0081] In this application, by creating a port for the IoT device access platform to connect to N TCP protocols, port reuse can be supported. When adding any new TCP protocol, there is no need to open a new port, which saves port resources of the IoT device access platform and avoids waste of port resources. At the same time, it can also reduce the maintenance workload of the IoT device access platform.

[0082] In practical implementation, a port can refer to the TCP listening port exposed by the backend service of the IoT device access platform. The N TCP protocols can include various custom TCP protocols, such as vehicle-to-everything (V2X) protocols and water meter protocols. The protocol fields of any TCP protocol can include header, trailer, and length fields, where these fields are defined by their start position and length within the TCP protocol. All business logic processing classes must implement a parent interface specified by the backend service and override the business logic processing methods defined in the parent interface.

[0083] In practical implementation, the starting position of each field in the protocol field can be calculated relative to the TCP protocol message header or message tail, or it can be calculated by the corresponding expression. In addition, the length of each field can be a certain value, or it can be calculated by the corresponding expression. This application does not limit this.

[0084] As an example, port 9807 can be configured as follows: Figure 2 The vehicle-to-everything (V2X) protocol is shown. Among them, Figure 2 Take the offset of the starting position in the protocol field relative to the TCP protocol header as an example.

[0085] In this application, by configuring the starting position and field length of the corresponding field in the TCP protocol, it is convenient to extract the corresponding field value in the TCP field stream according to the configured starting position and field length.

[0086] In one implementation, the visual configuration page may include, but is not limited to: port configuration items, protocol configuration items, protocol field configuration items, and business logic processing class configuration items. Specifically, the port configuration item can configure one port. The protocol configuration item can configure N protocols; when N is greater than or equal to 2, the port can be used as a multiplexed port. The protocol field configuration item can configure M fields of any TCP protocol, where the M fields include a header, a trailer, and a length, i.e., M is an integer greater than or equal to 3. The business logic processing class configuration item can configure one business logic processing field of any TCP protocol.

[0087] As an example, the main signaling and pseudo-IP fields for any TCP protocol can also be configured in the protocol field configuration item; that is, the M fields also include the main signaling and pseudo-IP fields. For example, Figure 2 The protocol fields in the vehicle-to-everything (V2X) protocol shown also include two fields: master signaling and pseudo IP.

[0088] In this application, a visual configuration page allows for the configuration of multiple TCP data decoding capabilities at the port level, with each capability corresponding to a specific TCP protocol. Furthermore, the visual configuration page enables the creation of configuration parameters for each port, facilitating the rapid addition of new TCP protocol formats or modification of existing ones. Terminal device manufacturers do not need to modify their existing custom TCP protocols, supporting the widespread deployment of corresponding TCP protocols. It is compatible with the TCP protocols of various terminal device manufacturers, eliminating the need for them to re-interface according to the protocols of the IoT device access platform. Moreover, the system automatically reads configuration parameters to parse the TCP streaming data received by the port, significantly reducing the amount of code and error rate when adding new TCP protocols, thus accelerating business development and reducing the probability of errors.

[0089] As an example, let's take a custom vehicle networking protocol as shown in Table 1, combined with... Figure 2 This section explains the instruction structure and names of the TCP protocol.

[0090] Table 1

[0091] 2 1 2 4 n 1 1 Baotou Lord's command Bao Chang fake IP content check wrap tail

[0092] Packet header and packet trailer: These refer to the frame boundaries of the data. The packet header occupies a length of 2 bytes, and the packet trailer occupies a length of 1 byte. The packet header is a fixed character (such as 0x29 0x29), and the packet trailer is represented by (0x0D).

[0093] Master signaling: occupies 1 byte and indicates the message type. For example, 80 indicates the location reporting information of the vehicle terminal, and 85 indicates the confirmation packet of the vehicle terminal sending instructions to the server.

[0094] Packet length: refers to the length of the data packet content, starting from the first byte after the packet length byte position and ending at the end of the packet, which occupies 2 bytes.

[0095] Checksum: This refers to the XOR operation of all bytes from the packet header up to the byte before the checksum, occupying 1 byte.

[0096] Fake IP address: refers to a fake IP address generated by converting the device ID number using a specified method. It occupies 4 bytes.

[0097] It should be understood that the general principle for customizing TCP protocol formats is that three fields must exist: header, trailer, and length. The header and trailer, as byte stream separators, are generally special characters and are 2-4 bytes in length.

[0098] In one implementation, after obtaining the configuration parameters, they can be initialized. For example, any pre-configured TCP protocol can be loaded; then, for any given TCP protocol, a decoder instance for that protocol can be generated; finally, based on the decoder instance for any given TCP protocol, a decoder for that given TCP protocol can be generated, completing the initialization of the configuration parameters. For example, as... Figure 3 As shown, the process of initializing configuration parameters includes loading the configured protocol and instantiating the corresponding decoder instance for each protocol to generate the corresponding decoder.

[0099] In this application, by initializing configuration parameters, any configured TCP protocol can be loaded and a decoder for any TCP protocol can be generated. That is, by parsing the visualized configuration parameters, the corresponding TCP protocol decoder can be automatically generated, which facilitates the subsequent decoding of the corresponding TCP protocol accessed by the port. Business developers do not need to handle the decoding logic. At the same time, the TCP data decoding logic and core business processing logic can be separated and decoupled, thereby reducing the workload and error probability of business developers, and also supporting the rapid access of new TCP protocols.

[0100] When port S120 receives TCP streaming data from the terminal device, it reads the target protocol field in the TCP streaming data and identifies the target TCP protocol of the TCP streaming data based on the target protocol field and configuration parameters.

[0101] In one implementation, the corresponding TCP protocol can be identified based on the packet header field. Specifically, when the port receives TCP streaming data from the terminal device, the target protocol field, i.e., the packet header field, can be read from the TCP streaming data. Based on the read packet header field and configuration parameters, the target TCP protocol of the TCP streaming data can be identified.

[0102] For example, if the header field in the configuration parameters is 0x29 0x29, indicating a vehicle-to-everything (V2X) protocol, then when the read header field is 0x29 0x29, it means the target TCP protocol is a V2X protocol.

[0103] In practice, the first two bytes of the TCP streaming data can be read to obtain the packet header field, which is the first two bytes of the TCP streaming data. If fewer than two bytes are read so far, the currently read bytes are buffered, and subsequent bytes are waited for to arrive until the first two bytes of the TCP streaming data are read.

[0104] For example, if only one byte is being read so far, which is the first byte of the TCP streaming data, then we can continue to wait for the subsequent bytes to arrive until the first two bytes of the TCP streaming data are read.

[0105] As an example, some common exception scenarios can be considered when identifying the target TCP protocol for TCP streaming data. For instance, if the protocol fields of any TCP protocol in the configuration parameters are traversed and no valid header field (such as 0x29 0x29) is found, and the received byte stream data has reached a certain quantity (such as exceeding 1MB), then the currently received TCP streaming data should be discarded to prevent memory overflow.

[0106] It should be understood that, in combination Figure 1 and Figure 3 As shown, step S120 is the protocol identification process executed by the server of the IoT device access platform during the decoding process.

[0107] S130. Parse the target TCP protocol to obtain the protocol content.

[0108] In one implementation, a decoder for the target TCP protocol can be invoked to parse the valid complete byte stream data in the target TCP protocol and obtain the protocol content. Any TCP protocol decoder can inherit from a base class, which can encapsulate processing logic for handling fragmented or concatenated packets, as well as exception handling. The criteria for determining fragmented or concatenated packets are the values ​​corresponding to the packet header, packet trailer, and packet length fields.

[0109] In related technologies, both the decoder and decoding logic require business developers to write their own code. In scenarios with multiple protocols on the same port, if different protocols are implemented by different business developers, it can easily lead to strong coupling. In this application, by calling the decoder of the target TCP protocol to parse the target TCP protocol, the legitimate and complete byte stream data in the target TCP protocol can be obtained, thus obtaining the protocol content of the target TCP protocol. That is, this application can decompose the decoding logic such as handling packet fragmentation and incomplete packet processing, providing scalability (meaning supporting the addition of decoding logic without modifying the original decoding code). Moreover, the decoding process in this application can be automatically implemented, automatically handling the packet fragmentation and incomplete packet problems of TCP data under the same port, ensuring correct data parsing. At the same time, it shields the decoding implementation logic from business developers, allowing them to use it out of the box, improving development efficiency and reducing the probability of errors.

[0110] In one applicable scenario provided in this application, the protocol content of the target TCP protocol can also be verified before performing step S140.

[0111] In one implementation, the configuration parameters also include a protocol content verification field for any TCP protocol.

[0112] In practice, the target protocol content verification class field of the target TCP protocol can be determined according to the configuration parameters; then, according to the target protocol content verification class field, the general verification processor is called to verify the protocol content; after the protocol content verification passes, step S140 is executed.

[0113] Among them, by calling the verification processor, the content verification fields of several common existing protocols can be verified.

[0114] In this application, by calling a general verification processor to verify the protocol content based on the target protocol content verification class field, the protocol content can be prevented from being tampered with.

[0115] S140. Based on the configuration parameters, determine the target business logic processing class field of the target TCP protocol.

[0116] In one implementation, the protocol field and business logic processing class field of any TCP protocol are already configured in the configuration parameters. Based on the configuration parameters, the target business logic processing class field of the target TCP protocol can be determined.

[0117] S150. Based on the target business logic processing class field, expose the business processing logic of the protocol content on the port in the form of a parent class interface.

[0118] In one implementation, the configuration parameters may further include any TCP protocol field conversion result class field. The protocol field conversion result class field can be a JSON class by default, in which case the key is the field name in the TCP protocol, and the value is the corresponding value of the protocol field; the protocol field conversion result class field can also be a custom VO class, which is not limited in this application.

[0119] In one implementation, the target protocol field conversion result class field of the target TCP protocol can be determined based on the configuration parameters; then, based on the target protocol field conversion result class field, the protocol content is converted into a protocol field conversion result class instance. For example, combined with... Figure 2-4 As shown, the target protocol fields can be converted into result class fields, and the fields and values ​​in the protocol content can be extracted, processed, and then assembled into a protocol field conversion result class instance.

[0120] In one implementation, a business logic processing class instance can be generated based on the target business logic processing class field. After decoding the TCP streaming data into a protocol field conversion result class instance, the protocol field conversion result class instance can be passed to the business logic processing class. This exposes the business processing logic of the protocol content on the port as a parent class interface, allowing business developers to focus solely on writing business logic code without needing to worry about the decoding logic, thus reducing their workload and the probability of errors.

[0121] In practice, after the protocol field conversion result class instance is passed to the business logic processing class instance, the business logic processing class instance can perform subsequent specific business logic processing.

[0122] In one applicable scenario provided by this application, when adding any TCP protocol, the configuration parameters can be updated in response to the addition of protocol configuration items, protocol field configuration items, and business logic processing class configuration items on the visual configuration page, thereby completing the new access of any TCP protocol.

[0123] When adding any new TCP protocol, business developers only need to focus on business logic processing. This significantly speeds up the integration of any new TCP protocol. In subsequent processes, the business logic processing class instance for the newly added TCP protocol, along with its corresponding business logic processing method, can be automatically generated using the business logic processing class field for that protocol.

[0124] As described above, this application supports port reuse and avoids port resource waste by creating port configuration parameters on a visual configuration page. It also provides a unified management interface, allowing business developers or administrators to understand which ports the IoT device access platform currently exposes and which protocols it supports. Furthermore, this configuration parameter can define a programming paradigm: decoding logic is handled by the IoT device access platform's server, while business logic is exposed to specific business developers through a parent class interface. Overall, this achieves decoupling of decoding and business processing logic between multiple protocols, reducing the probability of errors caused by mutual interference. This avoids situations where TCP messages cannot be correctly parsed, leading to message omissions or message processing errors.

[0125] Figure 5 This diagram illustrates a structural block diagram of a TCP data parsing and processing apparatus according to an embodiment of this application. Figure 5 As shown, the device may include:

[0126] The processing unit 210 is used to obtain the configuration parameters of the port of the IoT device access platform and initialize the configuration parameters. The configuration parameters are created based on the various configuration items on the visual configuration page. The configuration parameters include N TCP protocols corresponding to the port, as well as the protocol field and business logic processing class field of any TCP protocol, where N is an integer greater than or equal to 1.

[0127] The identification unit 220 is used to read the target protocol field in the TCP streaming data when the port receives TCP streaming data from the terminal device, and identify the target TCP protocol of the TCP streaming data according to the target protocol field and configuration parameters.

[0128] The parsing unit 230 is used to parse the target TCP protocol to obtain the protocol content; determine the target business logic processing class field of the target TCP protocol according to the configuration parameters; and expose the business processing logic of the protocol content on the port in the form of a parent class interface according to the target business logic processing class field.

[0129] In one implementation, the protocol fields of any TCP protocol include three fields: header, trailer, and length, with the target protocol field being the header field; the identification unit 220 is specifically used for:

[0130] Read the packet header fields from TCP streaming data;

[0131] Based on the packet header fields and configuration parameters, identify the target TCP protocol for TCP streaming data.

[0132] In one embodiment, the identification unit 220 is specifically used for:

[0133] Read the first two bytes of the TCP streaming data to obtain the packet header field;

[0134] If less than two bytes are read at the moment, the currently read bytes are buffered, and subsequent bytes are waited for to arrive until the first two bytes of the TCP streaming data are read.

[0135] In one embodiment, the processing unit 210 is specifically used for:

[0136] Load any TCP protocol;

[0137] For any given TCP protocol, generate a decoder instance for that specific TCP protocol.

[0138] Generate a decoder for any TCP protocol based on a decoder instance for any TCP protocol.

[0139] In one implementation, the parsing unit 230 is specifically used for:

[0140] Call the decoder of the target TCP protocol to parse the valid complete byte stream data in the target TCP protocol and obtain the protocol content.

[0141] In one implementation, the configuration parameters further include a protocol field conversion result field of any TCP protocol; the parsing unit 230 is specifically used for:

[0142] Based on the configuration parameters, determine the target protocol field conversion result class field of the target TCP protocol;

[0143] Based on the target protocol field conversion result class field, convert the protocol content into a protocol field conversion result class instance;

[0144] Generate an instance of the business logic processing class based on the target business logic processing class field;

[0145] By passing the instance of the protocol field conversion result class to the business logic processing class, the business processing logic of the protocol content is exposed on the port in the form of a parent class interface.

[0146] In one implementation, the configuration parameters further include a protocol content verification field for any TCP protocol; the parsing unit 230 is also used for:

[0147] Based on the configuration parameters, determine the target protocol content verification class field of the target TCP protocol;

[0148] Based on the target protocol content verification class field, call the general verification processor to verify the protocol content;

[0149] After the protocol content verification is successful, the target business logic processing class field of the target TCP protocol is determined according to the configuration parameters.

[0150] In one embodiment, the processing unit 210 is further configured to:

[0151] When a new TCP protocol is added, the configuration parameters are updated in response to any new operations on the protocol configuration items, protocol field configuration items, and business logic processing class configuration items on the visual configuration page.

[0152] The functions of each unit in the devices of this application embodiment can be found in the corresponding descriptions in the above methods, and will not be repeated here.

[0153] Figure 6 A structural block diagram of a computer device according to an embodiment of this application is shown. Figure 6 As shown, the computer device includes a memory 310 and a processor 320. The memory 310 stores instructions, which are loaded and executed by the processor 320 to implement the TCP data parsing and processing method in the above embodiment. The number of memories 310 and processors 320 can be one or more.

[0154] The computer device also includes:

[0155] The communication interface 330 is used to communicate with external devices and perform data exchange and transmission.

[0156] If the memory 310, processor 320, and communication interface 330 are implemented independently, they can be interconnected via a bus to communicate with each other. This bus can be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Architecture (EISA) bus, etc. This bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 6 The bus is represented by a single thick line, but this does not mean that there is only one bus or one type of bus.

[0157] Optionally, in a specific implementation, if the memory 310, processor 320 and communication interface 330 are integrated on a single chip, the memory 310, processor 320 and communication interface 330 can communicate with each other through an internal interface.

[0158] This application provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the method provided in this application.

[0159] This application also provides a chip, which includes a processor for calling and executing instructions stored in a memory, causing a communication device with the chip installed to execute the method provided in this application.

[0160] This application also provides a chip, including: an input interface, an output interface, a processor, and a memory. The input interface, output interface, processor, and memory are connected through an internal connection path. The processor is used to execute code in the memory. When the code is executed, the processor is used to execute the method provided in the application embodiment.

[0161] It should be understood that the aforementioned processor can be a Central Processing Unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. General-purpose processors can be microprocessors or any conventional processor. It is worth noting that the processor can be a processor supporting the Advanced Reduced Instruction Set Computing (RISC) machine (ARM) architecture.

[0162] Further, optionally, the aforementioned memory may include read-only memory and random access memory, and may also include non-volatile random access memory. The memory may be volatile or non-volatile, or may include both. Non-volatile memory may include read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), or flash memory. Volatile memory may include random access memory (RAM), which serves as an external cache. Many forms of RAM are available by way of example, but not limitation. Examples include static random access memory (SRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate synchronous dynamic random access memory (DDR SDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchronous linked dynamic random access memory (SLDRAM), and direct rambus RAM (DR RAM).

[0163] In the above embodiments, implementation can be achieved, in whole or in part, through software, hardware, firmware, or any combination thereof. When implemented using software, it can be implemented, in whole or in part, as a computer program cosmetic. A computer program cosmetic includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the processes or functions according to this application are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transferred from one computer-readable storage medium to another.

[0164] In the description of this specification, the references to terms such as "one embodiment," "some embodiments," "example," "specific example," or "some examples," etc., indicate that a specific feature, structure, material, or characteristic described in connection with that embodiment or example is included in at least one embodiment or example of this application. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in one or more embodiments or examples. Moreover, without contradiction, those skilled in the art can combine and integrate the different embodiments or examples described in this specification, as well as the features of those different embodiments or examples.

[0165] Furthermore, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include at least one of that feature. In the description of this application, "a plurality of" means two or more, unless otherwise explicitly specified.

[0166] Any process or method description in the flowchart or otherwise herein can be understood as representing a module, segment, or portion of code comprising one or more executable instructions for implementing a particular logical function or process. Furthermore, the scope of the preferred embodiments of this application includes additional implementations in which functions may be performed not in the order shown or discussed, including substantially simultaneously or in reverse order depending on the functionality involved.

[0167] The logic and / or steps represented in the flowchart or otherwise described herein, for example, can be considered as a sequenced list of executable instructions for implementing logical functions, and can be embodied in any computer-readable medium for use by, or in conjunction with, an instruction execution system, apparatus or device (such as a computer-based system, a processor-included system or other system that can fetch and execute instructions from, an instruction execution system, apparatus or device).

[0168] It should be understood that various parts of this application can be implemented using hardware, software, firmware, or a combination thereof. In the above embodiments, multiple steps or methods can be implemented using software or firmware stored in memory and executed by a suitable instruction execution system. All or part of the steps of the methods in the above embodiments can be implemented by a program instructing related hardware, the program being stored in a computer-readable storage medium, which, when executed, includes one or a combination of the steps of the method embodiments.

[0169] Furthermore, the functional units in the various embodiments of this application can be integrated into a processing module, or each unit can exist physically separately, or two or more units can be integrated into a module. The integrated module can be implemented in hardware or as a software functional module. If the integrated module is implemented as a software functional module and sold or used as an independent cosmetic product, it can also be stored in a computer-readable storage medium. This storage medium can be a read-only memory, a disk, or an optical disk, etc.

[0170] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any person skilled in the art can easily conceive of various variations or substitutions within the technical scope disclosed in this application, and these should all be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.

Claims

1. A method for parsing and processing TCP data, characterized in that, include: Obtain the configuration parameters of the port of the IoT device access platform, and initialize the configuration parameters. The configuration parameters are created based on the various configuration items on the visual configuration page. The configuration parameters include N TCP protocols corresponding to the port, as well as the protocol field and business logic processing class field of any TCP protocol, where N is an integer greater than or equal to 1. When the port receives TCP streaming data from the terminal device, it reads the target protocol field in the TCP streaming data and identifies the target TCP protocol of the TCP streaming data based on the target protocol field and the configuration parameters. Parse the target TCP protocol to obtain the protocol content; Based on the configuration parameters, determine the target business logic processing class field of the target TCP protocol; Based on the target business logic processing class field, the business processing logic of the protocol content is exposed on the port in the form of a parent class interface.

2. The method according to claim 1, characterized in that, The protocol fields of any of the TCP protocols include three fields: header, trailer, and length, wherein the target protocol field is the header field; Read the target protocol field from the TCP streaming data, and identify the target TCP protocol of the TCP streaming data based on the target protocol field and the configuration parameters, including: Read the packet header fields from the TCP streaming data; Based on the packet header field and the configuration parameters, the target TCP protocol of the TCP streaming data is identified.

3. The method according to claim 2, characterized in that, Reading the header fields of the TCP streaming data includes: Read the first two bytes from the TCP streaming data to obtain the packet header field; If less than two bytes are read at the moment, the currently read bytes are buffered, and subsequent bytes are waited for to arrive until the first two bytes of the TCP streaming data are read.

4. The method according to claim 1, characterized in that, Initializing the configuration parameters includes: Load any of the aforementioned TCP protocols; For any one of the TCP protocols, generate a decoder instance for that TCP protocol; Generate a decoder for any TCP protocol based on any TCP protocol decoder instance.

5. The method according to claim 4, characterized in that, Parsing the target TCP protocol yields the following protocol content: The decoder of the target TCP protocol is invoked to parse the valid complete byte stream data in the target TCP protocol and obtain the protocol content.

6. The method according to claim 1, characterized in that, The configuration parameters also include any of the TCP protocol's protocol field conversion result fields; Based on the target business logic processing class field, the business processing logic of the protocol content is exposed on the port in the form of a parent class interface, including: Based on the configuration parameters, determine the target protocol field conversion result class field of the target TCP protocol; Based on the target protocol field conversion result class field, the protocol content is converted into a protocol field conversion result class instance; Generate a business logic processing class instance based on the target business logic processing class field; The instance of the protocol field conversion result class is passed to the business logic processing class, thereby exposing the business processing logic of the protocol content on the port in the form of a parent class interface.

7. The method as described in claim 1, characterized in that, The configuration parameters also include any of the TCP protocol's protocol content verification fields; the method further includes: Based on the configuration parameters, determine the target protocol content verification class field of the target TCP protocol; Based on the target protocol content verification class field, the general verification processor is invoked to verify the protocol content; After the protocol content verification is successful, the target business logic processing class field of the target TCP protocol is determined according to the configuration parameters.

8. The method according to any one of claims 1-7, characterized in that, The method further includes: When any new TCP protocol is added, the configuration parameters are updated in response to the addition of new protocol configuration items, protocol field configuration items, and business logic processing class configuration items on the visual configuration page.

9. A TCP data parsing and processing apparatus, characterized in that, include: The processing unit is used to obtain the configuration parameters of the port of the IoT device access platform, and initialize the configuration parameters. The configuration parameters are created based on the various configuration items on the visual configuration page. The configuration parameters include N TCP protocols corresponding to the port, as well as the protocol field and business logic processing class field of any TCP protocol, where N is an integer greater than or equal to 1. The identification unit is used to read the target protocol field in the TCP streaming data when the port receives TCP streaming data from the terminal device, and identify the target TCP protocol of the TCP streaming data according to the target protocol field and the configuration parameters. The parsing unit is used to parse the target TCP protocol and obtain the protocol content; Based on the configuration parameters, determine the target business logic processing class field of the target TCP protocol; Based on the target business logic processing class field, the business processing logic of the protocol content is exposed on the port in the form of a parent class interface.

10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when run on a computer, implements the method as described in any one of claims 1-8.

Citation Information

Patent Citations

  • Message transmission method and device based on TCP protocol

    CN110086703A

  • Method and device for equipment to actively register to Internet of Things platform, equipment and medium

    CN114244648A