CN110875897B - Data transmission method, device, server and storage medium - Google Patents

Data transmission method, device, server and storage medium Download PDF

Info

Publication number
CN110875897B
CN110875897B CN201810997148.5A CN201810997148A CN110875897B CN 110875897 B CN110875897 B CN 110875897B CN 201810997148 A CN201810997148 A CN 201810997148A CN 110875897 B CN110875897 B CN 110875897B
Authority
CN
China
Prior art keywords
protocol
processing unit
communication channel
unit
data
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201810997148.5A
Other languages
Chinese (zh)
Other versions
CN110875897A (en
Inventor
范阿冬
吕建文
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Alibaba Group Holding Ltd
Original Assignee
Alibaba Group Holding Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Alibaba Group Holding Ltd filed Critical Alibaba Group Holding Ltd
Priority to CN201810997148.5A priority Critical patent/CN110875897B/en
Publication of CN110875897A publication Critical patent/CN110875897A/en
Application granted granted Critical
Publication of CN110875897B publication Critical patent/CN110875897B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L69/00Network arrangements, protocols or services independent of the application payload and not provided for in the other groups of this subclass
    • H04L69/18Multiprotocol handlers, e.g. single devices capable of handling multiple protocols
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L69/00Network arrangements, protocols or services independent of the application payload and not provided for in the other groups of this subclass
    • H04L69/24Negotiation of communication capabilities

Abstract

The embodiment of the application provides a data transmission method, a data transmission device, a server and a storage medium, so as to support different protocols. The method comprises the following steps: transmitting a data message in a communication channel; selecting a processing unit of the communication channel according to the protocol of the data message to form a communication channel processed by a corresponding protocol; and processing the data message by adopting a processing unit in the communication channel processed by the protocol. Therefore, different ports do not need to be set for different protocols, and the ports can support different protocols by selecting the processing units in the communication channels, so that the reusability of the ports is improved.

Description

Data transmission method, device, server and storage medium
Technical Field
The present application relates to the field of computer technologies, and in particular, to a data transmission method, a data transmission apparatus, a server, and a storage medium.
Background
The Internet of things (IoT) is an Internet with which things are connected, and with the rise of the Internet of things, internet of things devices are increasingly diversified. An application layer Protocol widely used in the field of internet of things is an MQTT (Message queue Telemetry Transport) Protocol, and requires that a cloud can support access of multiple different protocols, such as supporting access of a TCP (Transmission Control Protocol), an encrypted TCP Protocol, and the like.
The server may use the MQTT access server to support access to a plurality of different protocols, where the different protocols are often handled using different ports. In order to provide a uniform access experience, the server often receives an access request by using the same domain name, and then routes the access request to the same backend application for processing. The backend application can monitor a plurality of ports simultaneously, each port processes different access protocols, but in actual processing, various firewall and gateway security policies of the network often increase restrictions on the use of the ports, for example, blocking the use of an unused port, for example, some firewalls may intercept a standard 1883 port of the MQTT protocol corresponding to the TCP access mode, for example, restricting specific transmission contents of the used port, for example, some firewalls or gateways may check whether 80 ports transmit the MQTT protocol, and the like.
Due to the limitation on the use of the ports, the actually available interfaces for transmitting data corresponding to the MQTT protocol are limited, and further, the support of different protocols is limited.
Disclosure of Invention
The embodiment of the application provides a data transmission method to support different protocols.
Correspondingly, the embodiment of the application also provides a data transmission device, a server and a storage medium, which are used for ensuring the realization and the application of the system.
In order to solve the above problem, an embodiment of the present application discloses a data transmission method, where the method includes: transmitting a data message in a communication channel; selecting a processing unit of the communication channel according to the protocol of the data message to form a communication channel processed by a corresponding protocol; and processing the data message by adopting a processing unit in the communication channel processed by the protocol.
Optionally, the processing unit includes: a protocol judging unit and a protocol processing unit; the protocol processing unit includes: a first protocol processing unit; the protocol judging unit is positioned before the first protocol processing unit in the communication channel.
Optionally, the selecting the processing unit of the communication channel according to the protocol of the data packet includes: analyzing the protocol of the data message by adopting the protocol judging unit; and determining a protocol processing unit required by the communication channel according to the analysis result, and removing the protocol judgment unit from the communication channel.
Optionally, the analyzing the protocol of the data packet by using the protocol determining unit includes: the protocol judging unit reads data content from a target byte of the data message; and judging the protocol of the data message according to the data content to generate a corresponding analysis result.
Optionally, the determining, according to the analysis result, a protocol processing unit required by the communication channel includes at least one of the following steps: if the protocol of the data message is determined to be a second protocol, acquiring a second protocol processing unit, and adding the second protocol processing unit before the first protocol processing unit of the communication channel; if the protocol of the data message is determined to be the third protocol, acquiring a third protocol processing unit, and adding the third protocol processing unit before the first protocol processing unit of the communication channel; and if the protocol of the data message is determined to comprise the second protocol and the third protocol, acquiring a second protocol processing unit and a third protocol processing unit, and sequentially adding the second protocol processing unit and the third protocol processing unit before the first protocol processing unit of the communication channel.
Optionally, the protocol determining unit includes: a first protocol judgment unit and a second protocol judgment unit; the processing unit selecting the communication channel according to the protocol of the data packet includes: reading data content from a target byte of the data message by using the first protocol judgment unit, and judging whether a protocol is a second protocol according to the data content; if the communication channel is not the second protocol, removing the first protocol judgment unit from the communication channel; if the protocol is the second protocol, adding a second protocol processing unit before a second protocol judgment unit of the communication channel, and removing the first protocol judgment unit from the communication channel; and processing the data message by adopting the second protocol processing unit to obtain processed message data.
Optionally, the selecting, according to the protocol of the data packet, the processing unit of the communication channel further includes: reading data content from a target byte of the data message by using the second protocol judgment unit, and judging whether a protocol is a third protocol according to the data content; if the protocol is not the third protocol, removing the second protocol judgment unit from the communication channel; if the protocol is the third protocol, adding a third protocol processing unit before the first protocol processing unit of the communication channel, and removing the second protocol judging unit from the communication channel.
Optionally, the method further includes: recording position information corresponding to a reading pointer in the data message; after the removing the protocol determination unit from the communication channel, the method further includes: and recovering the position of the read pointer in the data message according to the position information.
Optionally, the method is applied to an access server based on the MQTT protocol for message queue telemetry transmission.
The embodiment of the application also discloses a data transmission device, which comprises: a transmission module, configured to transmit a data packet in a communication channel; the processing unit selection module is used for selecting the processing unit of the communication channel according to the protocol of the data message to form the communication channel processed by the corresponding protocol; and the data processing module is used for processing the data message by adopting a processing unit in the communication channel processed by the protocol.
Optionally, the processing unit includes: a protocol judging unit and a protocol processing unit; the protocol processing unit includes: a first protocol processing unit; the protocol judging unit is positioned before the first protocol processing unit in the communication channel.
Optionally, the processing unit selection module includes: the protocol judgment submodule is used for analyzing the protocol of the data message by adopting the protocol judgment unit; and the unit selection submodule is used for determining a protocol processing unit required by the communication channel according to the analysis result and removing the protocol judgment unit from the communication channel.
Optionally, the protocol determining sub-module is configured to read data content from a target byte of the data packet by using the protocol determining unit; and judging the protocol of the data message according to the data content to generate a corresponding analysis result.
Optionally, the unit selection sub-module is configured to, if it is determined that the protocol of the data packet is a second protocol, obtain a second protocol processing unit, and add the second protocol processing unit before the first protocol processing unit of the communication channel; if the protocol of the data message is determined to be the third protocol, acquiring a third protocol processing unit, and adding the third protocol processing unit before the first protocol processing unit of the communication channel; and if the protocol of the data message is determined to comprise the second protocol and the third protocol, acquiring a second protocol processing unit and a third protocol processing unit, and sequentially adding the second protocol processing unit and the third protocol processing unit before the first protocol processing unit of the communication channel.
Optionally, the protocol determining unit includes: a first protocol judgment unit and a second protocol judgment unit; the processing unit selection module comprises: the first judging submodule is used for reading data content from a target byte of the data message by adopting the first protocol judging unit and judging whether a protocol is a second protocol according to the data content; the unit processing submodule is used for removing the first protocol judging unit from the communication channel if the first protocol judging unit is not the second protocol; if the protocol is the second protocol, adding a second protocol processing unit before a second protocol judgment unit of the communication channel, and removing the first protocol judgment unit from the communication channel; and the data processing module is used for processing the data message by adopting the second protocol processing unit to obtain processed message data.
Optionally, the processing unit selection module further includes: a second judging submodule, configured to read data content from a target byte of the data packet by using the second protocol judging unit, and judge whether a protocol is a third protocol according to the data content; the unit processing submodule is further configured to remove the second protocol determination unit from the communication channel if the second protocol determination unit is not the third protocol; if the protocol is the third protocol, adding a third protocol processing unit before the first protocol processing unit of the communication channel, and removing the second protocol judgment unit from the communication channel.
Optionally, the processing unit selecting module is further configured to record position information corresponding to the read pointer in the data packet; and after removing the protocol judgment unit from the communication channel, recovering the position of the read pointer in the data message according to the position information.
Optionally, the method is applied to an access server based on the MQTT protocol for message queue telemetry transmission.
The embodiment of the application also discloses a server, which includes: a processor; and a memory having executable code stored thereon, which when executed, causes the processor to perform a data transmission method as described in one or more of the embodiments of the present application.
One or more machine-readable media having stored thereon executable code that, when executed, causes a processor to perform a data transmission method as described in one or more of the embodiments of the present application are also disclosed.
Compared with the prior art, the embodiment of the application has the following advantages:
in the embodiment of the application, the data message is transmitted between the device and the server through the communication channel, and then the processing unit of the communication channel can be dynamically selected based on the protocol of the data message to obtain the communication channel processed by the corresponding protocol, so that different ports do not need to be set for different protocols, and the ports can support different protocols by selecting the processing unit in the communication channel, thereby improving the reusability of the ports.
Drawings
FIG. 1 is a schematic illustration of a communication channel according to an embodiment of the present application;
FIG. 2 is a flow chart illustrating steps of an embodiment of a data transmission method of the present application;
FIG. 3A is a diagram illustrating various examples of communication channels in an embodiment of the present application
FIG. 3B is a flow chart illustrating steps in an alternative embodiment of a data transmission method of the present application;
FIGS. 4A-4D are diagrams of examples of communication channel processing in embodiments of the present application;
FIG. 4E is a flowchart illustrating steps in an alternative embodiment of a method for data transmission according to the present application;
FIG. 5 is a flowchart illustrating steps of an embodiment of a data transmission method applied to an MQTT scenario according to the present application;
FIG. 6 is a schematic diagram of various communication channel examples applied to an MQTT scenario in an embodiment of the present application;
FIG. 7 is a block diagram of an embodiment of a data transmission device according to the present application;
FIG. 8 is a block diagram of an alternative embodiment of a data transmission device according to the present application;
FIG. 9 is a block diagram of an alternate embodiment of a data transmission device according to the present application;
fig. 10 is a schematic structural diagram of an apparatus according to an embodiment of the present application.
Detailed Description
In order to make the aforementioned objects, features and advantages of the present application more comprehensible, the present application is described in further detail with reference to the accompanying drawings and the detailed description.
The embodiment of the application can be applied to the technology of the Internet of things. In an application scenario of the internet of things, an electronic device can access a server through an access server, so that data interaction is achieved, and the server can manage the electronic device, wherein the electronic device comprises an IoT device.
In order to realize the multiplexing of the corresponding port of the access server to different protocols, a communication channel of the port can be set to support the dynamic selection of the processing unit, thereby improving the access capability to different protocols. Reference is made to the schematic diagram of the communication channel shown in fig. 1. The communication channel takes the channel data chain processing model as an example, and the processing unit can be used as a node on the communication channel link. Wherein the processing units comprise processing unit 01-processing unit 05, the processing unit 01, the processing unit 02 and the processing unit 03 are located in a communication channel, and the processing unit 04 and the processing unit 05 are not in the communication channel. The processing units are not fixed as indicated by the dashed lines in fig. 1, and the processing units are adjustable on the communication channel, for example, the processing unit 04 is added to the communication channel, and for example, the processing unit 05 originally in the communication channel is removed, so that the communication channel as shown in fig. 1 is obtained.
Different processing units have different functions, and in the embodiment of the present application, the processing unit includes: a protocol judging unit and a protocol processing unit. The protocol judging unit is used for judging a protocol corresponding to the data message, such as judging whether the data message adopts a Transport Layer Security (TLS) protocol, an MQTT protocol and the like; the protocol processing unit is used for analyzing and processing the data message of the corresponding protocol, such as a TLS protocol processing unit for processing a TLS protocol, an MQTT protocol processing unit for processing an MQTT protocol, and the like. The protocol processing unit includes: a first protocol processing unit; the first protocol processing unit is a processing unit of a communication protocol necessary in an interaction process of the device and the server, and can be specifically determined according to requirements. For example, if the access server is constructed based on the MQTT protocol, the MQTT protocol is a necessary communication protocol, and the first protocol processing unit is an MQTT protocol processing unit.
In the actual processing, due to the requirements of devices, networks, data and the like, sometimes other protocols are encapsulated in addition to the necessary communication protocol for transmitting the data message, so that the communication is written to the processing unit which can be dynamically selected based on the protocol used by the data message, and the protocol judgment unit is located before the first protocol processing unit in the communication channel, so that the protocol used by the data message is judged by the protocol judgment unit first, and then whether other protocol processing units need to be added is determined. And after the protocol judgment is completed, the protocol judgment unit can be deleted from the communication channel to form a communication channel corresponding to the protocol processing, and the data message is processed by one or more protocol processing units.
Referring to fig. 2, a flowchart illustrating steps of an embodiment of a data transmission method according to the present application is shown.
Step 202, transmitting the data message in a communication channel.
The port of the device may establish a communication channel with the port of the access server to transmit the data packet, and the port may be a general port, which is not limited in this embodiment of the present application. After the communication channel is established and initialized, the data message can be transmitted, wherein the data message can be transmitted by streaming transmission, and the data message can be a data stream.
And 204, selecting the processing unit of the communication channel according to the protocol of the data message to form the communication channel processed by the corresponding protocol.
For the data message received by the communication channel, the protocol corresponding to the data message can be detected, so as to determine the required processing unit, and the processing unit of the communication channel is selected accordingly, and the communication channel processed by the corresponding protocol is formed according to the protocol corresponding to the data message, so that the corresponding protocol can be analyzed and the data message can be processed.
In an optional embodiment, the processing unit selecting the communication channel according to a protocol of the data packet includes: analyzing the protocol of the data message by adopting the protocol judging unit; and determining a protocol processing unit required by the communication channel according to the analysis result, and removing the protocol judgment unit from the communication channel.
After the communication channel is constructed, the communication channel comprises a protocol processing unit and a protocol judging unit, a data message is firstly input into the protocol judging unit, the protocol judging unit can analyze the protocol of the data message, wherein the contents of the data messages of different protocols in target bytes are different, so that the data content can be read from the target byte of the data message, for example, the data content in the first byte of the data message, and then the protocol of the data message is judged according to the data content to generate a corresponding analysis result. Then, the protocol processing unit required by the communication channel may be determined according to the analysis result, and different protocols correspond to different protocol processing units, for example, if the protocol processing unit included in the initial construction of the communication channel is the first protocol processing unit, other protocol processing units may be added according to the analyzed and determined protocol, or only the first protocol processing unit may be retained. After the protocol judgment unit finishes the protocol judgment of the data message, the communication protocol required to be processed by the communication channel is obtained, and the protocol does not need to be judged again for the subsequent data message, so the protocol judgment unit can be removed from the communication channel. Therefore, the communication channel which has recognized the protocol processing of the protocol includes the first protocol processing unit and possibly other protocol processing units.
Step 206, processing the data packet by using the processing unit in the communication channel processed by the protocol.
After determining the protocol according to the data message and adjusting the communication channel, the data message can be sequentially processed by adopting each protocol processing unit in the communication channel to obtain the analyzed data message. Therefore, the processing unit of the communication channel is dynamically selected, so that the communication channel can process the processing messages of various protocols, different ports do not need to be set based on different protocols, and the reusability of the ports is improved.
In each embodiment of the present application, a communication channel in an initialization process includes a protocol determination unit and a necessary protocol processing unit, and then a protocol determination unit is added or maintained according to a protocol of a data packet and the determined protocol determination unit is deleted, so that a communication channel formed by one or more protocol processing units is finally obtained, and then it can be considered that the communication channel is completely constructed.
In one example, the communication channel includes a protocol determining unit and a first protocol processing unit, the protocol determining unit reads data content in a target byte of a data packet, and then determines a protocol corresponding to the data packet according to the data content of the target byte, for example, a second protocol, a third protocol, etc., and then may add a corresponding protocol processing unit, such as the second protocol processing unit and the third protocol processing unit, to the front of the first protocol processing unit, and delete the protocol determining unit from the communication channel.
The protocol processing unit required for determining the communication channel according to the analysis result comprises at least one of the following steps: if the protocol of the data message is determined to be a second protocol, acquiring a second protocol processing unit, and adding the second protocol processing unit before the first protocol processing unit of the communication channel; if the protocol of the data message is determined to be the third protocol, acquiring a third protocol processing unit, and adding the third protocol processing unit before the first protocol processing unit of the communication channel; and if the protocol of the data message is determined to comprise the second protocol and the third protocol, acquiring a second protocol processing unit and a third protocol processing unit, and sequentially adding the second protocol processing unit and the third protocol processing unit before the first protocol processing unit of the communication channel.
Referring to fig. 3B, a flowchart illustrating steps of an alternative embodiment of a data transmission method of the present application is shown.
Step 302, a data packet is transmitted in a communication channel.
The port of the device can establish a communication channel with the port of the access server to transmit data stream, the protocol of the data message in the data stream can be analyzed by the protocol judgment unit, the protocol processing unit required by the communication channel is determined according to the analysis result, and then the protocol judgment unit is removed from the communication channel.
As in the schematic diagram of the communication channel example shown in fig. 3A. The initial communication channel comprises a protocol judging unit and a first protocol processing unit.
Step 304, the protocol determining unit reads the data content from the target byte of the data packet.
Step 306, judging the protocol of the data message according to the data content, and generating a corresponding analysis result;
the data packets of different protocols have different contents in the target byte, so that the data content can be read from the target byte of the data packet, for example, the data content in the first byte of the data packet is read, and then the protocol of the data packet is determined according to the data content to generate a corresponding analysis result.
If the data content meets the first condition, go to step 308; if the data content meets the second condition, go to step 310; if the data content meets the third condition, go to step 312; if the data content meets the fourth condition, go to step 314.
Step 308, removing the protocol determining unit to obtain the first type communication channel.
If the protocol judging unit judges that the data content meets the first condition, other protocol processing units are not needed to be added at the moment, and only the protocol judging unit is removed to obtain the first-class communication channel.
Step 310, add a second protocol processing unit before the first protocol processing unit, and remove the protocol determining unit to obtain a second type communication channel.
If the protocol judging unit judges that the data content meets the second condition, the data message adopts a second protocol, at this time, a second protocol processing unit can be added before the first protocol processing unit, and the protocol judging unit is removed, so that a second type communication channel is obtained.
In step 312, a third protocol processing unit may be added before the first protocol processing unit, and the protocol determining unit is removed to obtain a third type communication channel.
If the protocol judging unit judges that the data content meets the third condition, the data message adopts a third protocol, at this moment, a third protocol processing unit can be added before the first protocol processing unit, and the protocol judging unit is removed, so as to obtain a third type communication channel.
And step 314, adding the second protocol processing unit and the third protocol processing unit in sequence before the first processing unit, and removing the protocol judging unit to obtain a fourth type communication channel.
If the protocol judging unit judges that the data content meets the fourth condition, the data message adopts the second protocol and the third protocol, the second protocol processing unit and the third protocol processing unit can be sequentially added before the first processing unit, and the protocol judging unit is removed to obtain a fourth type communication channel.
Step 316, processing the data packet by using the processing unit in the communication channel processed by the protocol.
After the processing unit in the communication channel is selected and various protocol processing units required by the data message are determined, the protocol processing unit in the communication channel can be used for processing the data message.
In the embodiment of the present application, in the process of analyzing the protocol of the data packet by the protocol determination unit, when the protocol determination unit reads data content from the target byte of the data packet, the position information corresponding to the read pointer in the data packet may be recorded. That is, the position of the read pointer is recorded when the protocol judging unit reads data. Therefore, after the protocol judgment unit finishes the judgment of the protocol and removes the protocol judgment unit from the communication channel, the position of the reading pointer is recovered in the data message according to the position information, the data message is continuously processed from the position before the judgment, the judgment of the protocol corresponding to the data message does not influence the processing of the data message, and the integrity of the data and the accuracy of the processing are ensured.
The method adopts a plurality of protocols for the data message, and usually the data message is encapsulated by a plurality of layers of protocols, so that the protocol of the data message can be judged as the second protocol in the actual processing, and then the protocol of the analyzed data message is judged after the data message is analyzed by the second protocol processing unit. Therefore, in another alternative embodiment, the protocol processing unit may include a plurality of protocol processing units, and different protocol processing units are used to perform judgment processing on different protocols to identify a data packet encapsulated by a multi-layer protocol.
Wherein, the protocol judging unit comprises: the first protocol judging unit and the second protocol judging unit sequentially comprise a first protocol judging unit, a second protocol judging unit and a first protocol processing unit in a communication channel. The processing unit selecting the communication channel according to the protocol of the data packet includes: reading data content from a target byte of the data message by adopting the first protocol judgment unit, and judging whether a protocol is a second protocol or not according to the data content; if the protocol is not the second protocol, deleting the first protocol judgment unit from the communication channel; if the protocol is the second protocol, adding a second protocol processing unit before a first protocol processing unit of the communication channel, and deleting the first protocol judging unit from the communication channel; and processing the data message by adopting the first protocol processing unit to obtain processed message data. Reading data content from a target byte of the data message by adopting the second protocol judgment unit, and judging whether a protocol is a third protocol or not according to the data content; if the protocol is not the third protocol, deleting the second protocol judgment unit from the communication channel; and if the protocol is the third protocol, adding a third protocol processing unit before the first protocol processing unit of the communication channel, and deleting the second protocol judging unit from the communication channel.
Referring to fig. 4E, a flowchart illustrating steps of another alternative embodiment of the data transmission method of the present application is shown.
Step 402, transmitting a data message in a communication channel.
The port of the device and the port of the access server can establish a communication channel to transmit data stream, the protocol of the data message in the data stream can be analyzed by the protocol judgment unit, the protocol processing unit required by the communication channel is determined according to the analysis result, and then the protocol judgment unit is removed from the communication channel.
The initial communication channel comprises a first protocol judging unit, a second protocol judging unit and a first protocol processing unit. As in the communication channel processing diagrams shown in fig. 4A to 4D, an example process of selecting a processing unit in a communication channel by the judgment of the first protocol judgment unit and the second protocol judgment unit is shown. So that different protocols can be identified by different protocol determination units and multi-layer protocols can be processed.
Step 404, reading data content from the target byte of the data packet by using the first protocol judgment unit.
Step 406, determining whether the protocol is a second protocol according to the data content;
the data packets of different protocols have different contents in the target byte, so the first protocol determining unit may read the data content from the target byte of the data packet based on the protocol to be determined, for example, read the data content in the first byte of the data packet, and then determine whether the protocol of the data packet is the second protocol according to the data content. Wherein the position information of the read pointer can be recorded when the first protocol judges the data content of the unit target byte.
If yes, namely the protocol of the data message is the second protocol, execute step 410; if not, i.e., the protocol of the datagram is not the second protocol, step 408 is performed,
step 408, removing the first protocol determination unit from the communication channel.
The first protocol judging unit finishes the judgment of the protocol corresponding to the data message, and can remove the first protocol judging unit from the communication channel. And the position of the read pointer can be recovered in the data message according to the position information recorded before, so that the data message can be recovered to be processed before judgment. As shown in fig. 4C and 4D, the first protocol determining unit is initially used to determine whether the packet belongs to the second protocol, and the first protocol determining unit may be deleted after determining that the packet does not belong to the second protocol, and then the second protocol determining unit may determine the protocol based on the data packet.
Step 410, adding a second protocol processing unit before a second protocol judging unit of the communication channel, and removing the first protocol judging unit from the communication channel.
Step 412, processing the data packet by using the second protocol processing unit to obtain processed packet data.
After the first protocol determining unit determines that the protocol of the data packet is the second protocol, a second protocol processing unit may be added before the second protocol determining unit of the communication channel, and the first protocol determining unit is removed from the communication channel. After the protocol is judged to be the second protocol as in fig. 4A and 4B, the second protocol processing unit is added before the second protocol judging unit, and the first protocol judging unit is deleted. And then, according to the position information recorded before, the position of the reading pointer is recovered in the data message, so that the data message is input into a second protocol processing unit for processing, and the data message encapsulated by a second protocol is analyzed to obtain processed message data. And processing the second protocol judgment unit by adopting the processed message data.
Step 414, reading the data content from the target byte of the data packet by using the second protocol judgment unit.
Step 416, determine whether the protocol is the third protocol according to the data content.
If the protocol based on the judgment data message is not the second protocol, the data message is input into a second protocol judgment unit; if the protocol based on the judgment data message is the second protocol, the data message is processed by the second protocol processing unit, and the processed message data is input into the second protocol judgment unit. The second protocol determining unit may read data content from a target byte of the data packet based on a protocol to be determined, for example, read data content in a first byte of the data packet, and then determine whether the protocol of the data packet is a third protocol according to the data content. Wherein the position information of the read pointer can be recorded when the second protocol judges the data content of the unit target byte.
If yes, namely the protocol of the data message is the third protocol, execute step 418; if not, that is, the protocol of the data packet is not the third protocol, go to step 420.
Step 418, add a third protocol processing unit before the first protocol processing unit of the communication channel, and remove the second protocol determining unit from the communication channel.
After the second protocol determining unit determines that the protocol of the data packet is the third protocol, a third protocol processing unit may be added before the first protocol processing unit of the communication channel, and the second protocol determining unit may be removed from the communication channel. After the protocol is judged to be the third protocol as in fig. 4A and 4C, the third protocol processing unit is added before the first protocol processing unit is added, and the second protocol judging unit is deleted. And then, according to the position information recorded before, the position of the reading pointer can be recovered in the data message, so that the data message is input into a third protocol processing unit for processing, the data message encapsulated by a third protocol is analyzed, the processed message data is obtained, and the processed message data is input into the first protocol processing unit for processing.
Step 420, removing the second protocol determining unit from the communication channel.
The second protocol judging unit completes the judgment of the protocol corresponding to the data message and can remove the second protocol judging unit from the communication channel. And the position of the read pointer can be recovered in the data message according to the position information recorded before, so that the data message can be processed before judgment. As shown in fig. 4B and fig. 4D, the second protocol determining unit is used to determine whether the data packet belongs to the third protocol, and the second protocol determining unit may be deleted after determining that the data packet does not belong to the third protocol, and then the data packet may be input to the first protocol processing unit for processing.
In combination with the above judgment process, for the case where the communication channel initially includes the first protocol judgment unit, the second protocol judgment unit, and the first protocol processing unit in sequence, based on different judgment results of the protocol judgment units, communication information composed of different protocol processing units can be finally obtained.
As shown in fig. 4A, first, the protocol of the data packet is determined to be the second protocol by the first protocol determining unit, where the position information of the read pointer is recorded when the target byte in the data packet is read; and then adding a second protocol processing unit before the second protocol judging unit, removing the first protocol judging unit, and restoring the position of a read pointer in the data message according to the position information recorded before, so that the data message can be input into the second protocol processing unit for processing. And inputting the processed data message into a second protocol judgment unit, reading the data content of the target byte of the processed data message by the second protocol judgment unit, recording the position information of the read pointer, adding a third protocol processing unit before the first protocol processing unit after judging that the protocol of the processed data message is a third protocol, deleting the second protocol judgment unit, and recovering the position of the read pointer in the processed data message, so that the processed data message is input into the third protocol processing unit, and the processed data message is input into the first protocol processing unit for processing after the processing of the third protocol processing unit is finished. Therefore, the data message in the communication channel is processed by the second protocol processing unit, the third protocol processing unit and the first protocol processing unit in sequence.
As shown in fig. 4B, first, the protocol of the data packet is determined to be the second protocol by the first protocol determining unit, where the position information of the read pointer is recorded when the target byte in the data packet is read; and then adding a second protocol processing unit before the second protocol judging unit, removing the first protocol judging unit, and restoring the position of a read pointer in the data message according to the position information recorded before, so that the data message can be input into the second protocol processing unit for processing. And inputting the processed data message into a second protocol judgment unit, reading the data content of the target byte of the processed data message by the second protocol judgment unit, recording the position information of the read pointer, deleting the second protocol judgment unit and recovering the position of the read pointer in the processed data message after judging that the protocol of the processed data message is not the third protocol, thereby inputting the processed data message into the first protocol processing unit for processing. So that the data packets in the communication channel are processed by the second protocol processing unit and the first protocol processing unit in sequence.
As shown in fig. 4C, it is first determined by the first protocol determining unit that the protocol of the data packet is not the second protocol, where the position information of the read pointer is recorded when the target byte in the data packet is read; and then removing the first protocol judgment unit, and recovering the position of the read pointer in the data message according to the position information recorded before. And then inputting the data message into a second protocol judgment unit, reading the data content of the target byte of the data message by the second protocol judgment unit, recording the position information of a reading pointer, adding a third protocol processing unit before the first protocol processing unit after judging that the protocol of the data message is a third protocol, deleting the second protocol judgment unit, and recovering the position of the reading pointer in the data message, so that the data message is input into the third protocol processing unit, and the data message is input into the first protocol processing unit for processing after the third protocol processing unit finishes processing. So that the data packet in the communication channel is processed by the third protocol processing unit and the first protocol processing unit in sequence.
As shown in fig. 4D, it is first determined by the first protocol determining unit that the protocol of the data packet is not the second protocol, where the position information of the read pointer is recorded when the target byte in the data packet is read; then, the first protocol judgment unit is removed, and the position of the read pointer in the data message is recovered according to the position information recorded before. And then inputting the data message into a second protocol judgment unit, reading the data content of the target byte of the data message and recording the position information of the reading pointer by the second protocol judgment unit, deleting the second protocol judgment unit and recovering the position of the reading pointer in the data message after judging that the protocol of the data message is not the third protocol, thereby inputting the data message into the first protocol processing unit for processing. So that data messages in the communication channel are processed by the first protocol processing unit.
Step 422, the processing unit in the communication channel processed by the protocol is used to process the data packet.
After the processing unit in the communication channel is selected and various protocol processing units required by the data message are determined, the protocol processing unit in the communication channel can be used for processing the data message.
The embodiment of the application can be applied to an MQTT (Message Queuing Telemetry Transport) technical scene, and an access server based on an MQTT protocol is adopted. Taking an access server of the MQTT protocol as an example, a necessary protocol processing unit in the communication channel is an MQTT protocol processing unit. Aiming at the data message transmitted by the TCP protocol, only the MQTT protocol processing unit is needed to process the data message; if the data message is transmitted in a TCP (transmission control protocol) mode encrypted by the TLS protocol, the TLS protocol needs to be processed firstly; if the data message is transmitted in an MQTT-over-WebSocket mode, processing a WebSocket protocol first, wherein the MQTT-over-WebSocket refers to a mode of transmitting MQTT protocol data based on a WebSocket session; if the data message is transmitted in an MQTT-over-WebSocket mode encrypted by the TLS protocol, the TLS protocol needs to be processed first, then the WebSocket protocol needs to be processed, and then the MQTT protocol is analyzed.
Therefore, after the device and the MQTT access server perform a communication channel through the port, the communication channel includes a first protocol determining unit, a second protocol determining unit, and an MQTT protocol processing unit, as shown in fig. 6.
Referring to fig. 5, a flowchart illustrating steps of an embodiment of a data transmission method applied to an MQTT scenario according to the present application is shown.
Step 502, transmitting a data packet in a communication channel.
The port of the equipment and the port of the MQTT access server can establish a communication channel, and the initial communication channel comprises a first protocol judging unit, a second protocol judging unit and an MQTT protocol processing unit. Then, the data message in the data stream is transmitted in the communication channel, and the data message is firstly input into the first protocol judgment unit.
Step 504, reading data content from the first byte of the data packet by using the first protocol determining unit, and recording position information of a read pointer.
Step 506, judging whether the protocol is a TLS protocol or not according to the data content;
the first protocol determining unit may determine whether it is a TLS encrypted connection. The data content may be read from the first byte of the data packet and the position of the current read pointer in the data stream is recorded to determine whether the data content is 0x16.
If yes, determining the TLS protocol, and performing step 510; if not, it is determined not to be the TLS protocol and step 508 may be performed.
In the TLS protocol, a handshake process is first performed, and then the Client sends a data packet "Client Hello", where the data packet starts with 0x16. If the data message of MQTT protocol is directly transmitted based on TCP protocol, the first data message of the data stream is MQTT Connect data message, and the data message starts with 0x 10. Therefore, by determining whether the first byte corresponds to 0x16 data content, it can be determined whether the TLS protocol is used.
Step 508, removing the first protocol determination unit from the communication channel, and restoring the position of the read pointer.
The first protocol judgment unit finishes the judgment of the TLS protocol corresponding to the data message, and can remove the first protocol judgment unit from the communication channel. And the position of the read pointer can be recovered in the data message according to the position information recorded before, so that the data message can be processed before judgment.
Step 510, adding a TLS protocol processing unit before a second protocol determining unit of the communication channel; and removing the first protocol judgment unit from the communication channel and recovering the position of the read pointer.
And step 512, processing the data message by using the TLS protocol processing unit to obtain processed message data.
After the first protocol judgment unit determines that the protocol of the data message is the TLS protocol, a TLS protocol processing unit can be added before a second protocol judgment unit of the communication channel, the first protocol judgment unit is removed from the communication channel, and the position of the read pointer can be recovered in the data message according to the position information recorded before, so that the data message is input into the TLS protocol processing unit for processing, the data message encapsulated by the TLS protocol is analyzed, and the processed message data is obtained. And processing the second protocol judgment unit by adopting the processed message data.
And 514, reading data content from the first byte of the data message by using the second protocol judgment unit, and recording position information of a read pointer.
And 516, judging whether the protocol is an MQTT-over-WebSocket protocol or not according to the data content.
If the protocol based on the judgment data message is not the TLS protocol, inputting the data message into a second protocol judgment unit; if the protocol of the data message is determined to be the TLS protocol based on the above, the data message is processed through the TLS protocol processing unit, and the message data after TLS processing is input into the second protocol determining unit. The second protocol judging unit is used for judging whether the protocol is the MQTT-over-WebSocket protocol. The data content can be read from the first byte of the data packet and the position of the current read pointer in the data stream is recorded. It is then determined whether the data content of the first byte is 0x47.
If yes, determining that the protocol of the data message is MQTT-over-WebSocket protocol, and executing a step 518; if not, the protocol of the data message is determined not to be the MQTT-over-WebSocket protocol, and step 520 is executed.
In the data transmission in the MQTT-over-WebSocket mode, connection is established based on a WebSocket Protocol, the WebSocket Protocol is established by a get request of HTTP (HyperText Transfer Protocol), and a first byte of the get request of the HTTP Protocol is 0x47. Therefore, the first byte of the MQTT-over-WebSocket mode is 0x47. If the data message of MQTT protocol is directly transmitted based on TCP protocol, the first data message of the data stream is MQTT Connect data message, and the data message starts with 0x 10.
Step 518, adding an MQTT-over-WebSocket protocol processing unit before the MQTT protocol processing unit of the communication channel; and removing the second protocol judgment unit from the communication channel and recovering the position of the read pointer.
After the second protocol judging unit determines that the protocol of the data message is the MQTT-over-WebSocket protocol, a WebSocket protocol processing unit can be added before the MQTT protocol processing unit of the communication channel. And removing the second protocol judgment unit from the communication channel, recovering the position of the reading pointer in the data message according to the position information recorded before, so as to input the data message into the WebSocket protocol processing unit for processing, analyzing the data message encapsulated by the MQTT-over-WebSocket protocol, obtaining processed message data, and inputting the processed message data into the MQTT protocol processing unit for processing.
Step 520, removing the second protocol determining unit from the communication channel, and recovering the position of the read pointer.
And the second protocol judging unit finishes the judgment of the protocol corresponding to the data message, wherein aiming at the condition that the protocol is not the MQTT-over-WebSocket protocol, other protocol processing units are not required to be added, the second protocol judging unit can be removed from the communication channel, and the position of the reading pointer can be recovered in the data message according to the position information recorded before, so that the data message can be recovered to be processed before the judgment.
Thereby, based on the processing of the first protocol judgment unit and the second protocol judgment unit, the protocol processing unit in the communication channel can be added or maintained, and the protocol judgment unit which completes the judgment is removed, and the processing of the communication channel is realized. As shown in fig. 6, a communication channel corresponding to MQTT protocol data transmitted based on a TCP manner is obtained; a communication channel based on a TCP protocol mode encrypted by a message TLS protocol; a communication channel based on an MQTT-over-WebSocket mode; and the communication channel is encrypted based on the TLS protocol and adopts an MQTT-over-WebSocket mode.
Aiming at data stream transmission in an MQTT-over-WebSocket mode based on TLS protocol encryption, from the perspective of a protocol stack, the TLS protocol and the MQTT-over-WebSocket protocol are in different levels, if MQTT protocol service data is compared into cakes, the TLS protocol is an outermost layer of package, and the MQTT-over-WebSocket is an inner layer of package; from the perspective of data flow, the data message in the data flow is analyzed and processed by the TLS protocol first, and then analyzed and processed by the WebSocket protocol, so that after the TLS protocol processing unit is judged and added in the first step, the data message is analyzed and processed by the TLS protocol processing unit, and the processed data is judged again to determine whether the data message is the MQTT-over-WebSocket protocol. Based on the above, it can be seen that the use of any one of the protocols from the perspective of the protocol stack corresponds to only one layer of wrapper.
In each embodiment of the present application, a communication channel in an initialization process includes a protocol determination unit and a necessary protocol processing unit, and then a protocol determination unit is added or maintained according to a protocol of a data packet and the determined protocol determination unit is deleted, so that a communication channel formed by one or more protocol processing units is finally obtained, and then it can be considered that the communication channel is completely constructed. The data stream in the communication channel does not change the protocol, the processing unit of the communication channel is dynamically selected, and the effect of improving the reusability of the port is achieved.
Step 522, the processing unit in the communication channel processed by the protocol is used to process the data packet.
If the communication channel is a communication channel based on TCP transmission, the data stream can be input into an MQTT protocol processing unit to obtain corresponding service data; if the communication channel is a communication channel based on a TCP protocol mode encrypted by a TLS protocol, the data stream can be input into a TLS protocol processing unit and then input into an MQTT protocol processing unit to obtain corresponding service data; if the communication channel is based on the MQTT-over-WebSocket mode, the data stream can be input into the WebSocket protocol processing unit and then input into the MQTT protocol processing unit to obtain corresponding service data; if the communication channel is an MQTT-over-WebSocket mode communication channel encrypted based on the TLS protocol, the data stream can be input into the TLS protocol processing unit, then input into the WebSocket protocol processing unit, and finally input into the MQTT protocol processing unit to obtain corresponding service data.
In the embodiment of the present application, different processing units form a communication channel of the channel processing unit chain, so that when one processing unit (node) is removed from the channel processing unit chain, the successor pointer of the successor node of the node to be deleted can be pointed to the successor node of the node to be deleted.
The position of the read pointer is used for storing the current read position in the data receiving buffer area, and the normal network data processing process is direct streaming processing without recording the read position. However, in the embodiment of the present application, since the data content of a part of bytes is read for protocol determination, and the data content corresponding to the bytes is also needed in the process of processing the data packet based on the protocol, the read position is to be rolled back to the position before the protocol determination after the determination is completed. For example, a segment of data packet includes 10 bytes of data content, the 1 st byte is taken in the determining process to determine what type of packet is, and after the determination is completed, the corresponding protocol processing unit is used to analyze the data packet, which cannot start from the 2 nd byte, but needs to go back to the 1 st byte for processing according to the read pointer, so as to ensure the integrity of the data packet and the accuracy of data packet analysis.
In the embodiment of the application, port multiplexing is performed based on a network protocol, for example, several different access protocols for the MQTT protocol, so that the specific access protocol used can be dynamically determined according to the characteristics of the required access protocol, and a corresponding channel processing model is established. For the protocol judging process, processing is carried out according to the characteristics of the protocol to be judged, for example, for several different access protocols of the MQTT protocol, two key characteristics of 'whether to use TLS' and 'whether to use WebSocket to establish connection' can be distinguished, and two protocol judging units are respectively used for judging; each protocol judging unit only needs to extract one byte in the channel data stream for judgment, so that the judging efficiency is very high, and the processing efficiency in the channel establishing process cannot be obviously influenced.
According to the embodiment of the application, when the channel is initially established, the specific protocol used is dynamically judged, and the corresponding protocol processing unit is added, so that the corresponding channel processing is established, once the channel processing is established, the data processing process in the subsequent communication channel does not need to be judged again, and therefore, the data processing efficiency of the subsequent process cannot be affected. Therefore, the method and the device realize that a single port simultaneously supports multiple access protocols, thereby increasing the convenience of access and better dealing with the condition of firewall port interception.
It should be noted that, for simplicity of description, the method embodiments are described as a series of acts or combination of acts, but those skilled in the art will recognize that the embodiments are not limited by the order of acts described, as some steps may occur in other orders or concurrently depending on the embodiments. Further, those of skill in the art will recognize that the embodiments described in this specification are presently preferred embodiments and that no particular act is required to implement the embodiments of the disclosure.
On the basis of the above embodiments, the present embodiment further provides a data transmission device, which is applied to a server, such as an MQTT access server.
Referring to fig. 7, a block diagram of a data transmission apparatus according to an embodiment of the present application is shown, which may specifically include the following modules:
a transmission module 702 is configured to transmit a data packet in a communication channel.
A processing unit selecting module 704, configured to select a processing unit of the communication channel according to the protocol of the data packet, so as to form a communication channel processed by a corresponding protocol.
A data processing module 706, configured to process the data packet by using a processing unit in the communication channel processed by the protocol.
In summary, a data packet is transmitted between a device and a server through a communication channel, and then a processing unit of the communication channel can be dynamically selected based on a protocol of the data packet, so as to obtain the communication channel processed by a corresponding protocol, thereby enabling the port to support different protocols by selecting the processing unit in the communication channel without setting different ports for different protocols, and improving the reusability of the port.
In the embodiment of the present application, the processing unit selecting module is further configured to record position information corresponding to a read pointer in the data message; and after removing the protocol judgment unit from the communication channel, recovering the position of the read pointer in the data message according to the position information.
Referring to fig. 8, a block diagram of an alternative embodiment of a data transmission device according to the present application is shown, which specifically includes the following modules:
a transmission module 702 is configured to transmit a data packet in a communication channel.
A processing unit selecting module 704, configured to select a processing unit of the communication channel according to the protocol of the data packet, so as to form a communication channel processed by a corresponding protocol.
A data processing module 706, configured to process the data packet by using a processing unit in the communication channel processed by the protocol.
Wherein the processing unit comprises: a protocol judging unit and a protocol processing unit; the protocol processing unit includes: a first protocol processing unit; the protocol judging unit is positioned before the first protocol processing unit in the communication channel.
The processing unit selection module 704 includes: a protocol determination sub-module 82, a unit selection sub-module 84, and a pointer processing sub-module 86, wherein:
a protocol judging sub-module 82, configured to analyze the protocol of the data packet by using the protocol judging unit;
a unit selection submodule 84, configured to determine, according to the analysis result, a protocol processing unit required by the communication channel; and removing the protocol judgment unit from the communication channel, and recovering the position of the read pointer in the data message according to the position information.
And a pointer processing sub-module 86, configured to record position information corresponding to the read pointer in the data packet. And after the unit selection submodule 84 removes the protocol determination unit from the communication channel, restoring the position of the read pointer in the data packet according to the position information.
The protocol judging submodule 82 is configured to read data content from a target byte of the data packet by using the protocol judging unit; and judging the protocol of the data message according to the data content to generate a corresponding analysis result.
The unit selection submodule 84 is configured to, if it is determined that the protocol of the data packet is the second protocol, acquire a second protocol processing unit, and add the second protocol processing unit before the first protocol processing unit of the communication channel; if the protocol of the data message is determined to be the third protocol, acquiring a third protocol processing unit, and adding the third protocol processing unit before the first protocol processing unit of the communication channel; and if the protocol of the data message is determined to comprise the second protocol and the third protocol, acquiring a second protocol processing unit and a third protocol processing unit, and sequentially adding the second protocol processing unit and the third protocol processing unit before the first protocol processing unit of the communication channel.
Referring to fig. 9, a block diagram of an alternative embodiment of a data transmission device according to the present application is shown, and specifically, the structure may include the following modules:
a transmission module 702 is configured to transmit a data packet in a communication channel.
A processing unit selecting module 704, configured to select a processing unit of the communication channel according to the protocol of the data packet, so as to form a communication channel processed by a corresponding protocol.
A data processing module 706, configured to process the data packet by using a processing unit in the communication channel processed by the protocol.
Wherein the processing unit comprises: a protocol judging unit and a protocol processing unit; the protocol processing unit includes: a first protocol processing unit; the protocol judging unit is positioned in front of the first protocol processing unit in the communication channel; the protocol judging unit includes: a first protocol judging unit and a second protocol judging unit.
The processing unit selection module 704 includes: a first judgment sub-module 92, a unit processing sub-module 94, a second judgment sub-module 96 and a pointer sub-module 98, wherein:
a first determining sub-module 92, configured to read data content from a target byte of the data packet by using the first protocol determining unit, and determine whether a protocol is a second protocol according to the data content;
a unit processing sub-module 94, configured to remove the first protocol determining unit from the communication channel if the first protocol determining unit is not the second protocol; if the protocol is the second protocol, adding a second protocol processing unit before a second protocol judgment unit of the communication channel, and removing the first protocol judgment unit from the communication channel; the data processing module 704 is configured to process the data packet by using the second protocol processing unit, so as to obtain processed packet data.
A second judging submodule 96, configured to read data content from the target byte of the data packet by using the second protocol judging unit, and judge whether a protocol is a third protocol according to the data content; the unit processing sub-module 94 is further configured to remove the second protocol determining unit from the communication channel if the second protocol is not the third protocol; if the protocol is the third protocol, adding a third protocol processing unit before the first protocol processing unit of the communication channel, and removing the second protocol judging unit from the communication channel.
The pointer submodule 98 is further configured to record position information corresponding to a read pointer in the data message; and the unit processing sub-module 94 recovers the position of the read pointer in the data packet according to the position information after removing the protocol determination unit from the communication channel.
The data transmission device of the embodiment of the application can be applied to an access server for transmitting MQTT based on message queue telemetry.
The embodiment of the application can be applied to an MQTT (Message queue Telemetry Transport) technical scene, and an access server based on an MQTT protocol is adopted. Taking an access server of the MQTT protocol as an example, the necessary protocol processing unit in the communication channel is an MQTT protocol processing unit. Aiming at the data message transmitted by the TCP protocol, only the MQTT protocol processing unit is needed to process the data message; if the data message is transmitted in a TCP (transmission control protocol) mode encrypted by the TLS protocol, the TLS protocol needs to be processed firstly; if the data message is transmitted in an MQTT-over-WebSocket mode, processing a WebSocket protocol first, wherein the MQTT-over-WebSocket refers to a mode of transmitting MQTT protocol data based on a WebSocket session; if the data message is transmitted in an MQTT-over-WebSocket mode encrypted by the TLS protocol, the TLS protocol needs to be processed first, then the WebSocket protocol needs to be processed, and then the MQTT protocol is analyzed.
Therefore, after the device and the MQTT access server perform a communication channel through the port, the communication channel includes a first protocol determining unit, a second protocol determining unit, and an MQTT protocol processing unit, as shown in fig. 6. If the data stream is a communication channel transmitted based on a TCP mode, the data stream can be input into an MQTT protocol processing unit to obtain corresponding service data; if the data stream is a communication channel based on a TLS protocol encrypted TCP protocol mode, the data stream can be input into a TLS protocol processing unit and then input into an MQTT protocol processing unit to obtain corresponding service data; if the communication channel is based on the MQTT-over-WebSocket mode, the data stream can be input into the WebSocket protocol processing unit and then input into the MQTT protocol processing unit to obtain corresponding service data; if the communication channel is an MQTT-over-WebSocket mode communication channel encrypted based on the TLS protocol, the data stream can be input into the TLS protocol processing unit, then input into the WebSocket protocol processing unit, and finally input into the MQTT protocol processing unit to obtain corresponding service data.
Aiming at data stream transmission in an MQTT-over-WebSocket mode based on TLS protocol encryption, from the perspective of a protocol stack, the TLS protocol and the MQTT-over-WebSocket protocol are in different levels, if MQTT protocol service data is compared into cakes, the TLS protocol is an outermost layer of package, and the MQTT-over-WebSocket is an inner layer of package; from the perspective of data flow, the data message in the data flow is analyzed and processed by the TLS protocol first, and then analyzed and processed by the WebSocket protocol, so that after the TLS protocol processing unit is judged and added in the first step, the data message is analyzed and processed by the TLS protocol processing unit, and the processed data is judged again to determine whether the data message is the MQTT-over-WebSocket protocol. Based on the above, it can be seen that the adoption of any one of the protocols from the perspective of the protocol stack corresponds to only one layer of packaging.
In the embodiment of the present application, different processing units form a communication channel of a channel processing unit chain, so that when one processing unit (node) is removed from the channel processing unit chain, the successor pointer of the successor node of the node to be deleted can point to the successor node of the node to be deleted.
The position of the read pointer is used for storing the current read position in the data receiving buffer area, and the normal network data processing process is direct streaming processing without recording the read position. However, in the embodiment of the present application, since the data content of a part of bytes is read for protocol determination, and the data content corresponding to the bytes is also needed in the process of processing the data packet based on the protocol, the read position is to be rolled back to the position before the protocol determination after the determination is completed. For example, a section of data packet includes 10 bytes of data content, the 1 st byte is taken in the judgment process to judge which type of packet is, after the judgment is completed, the corresponding protocol processing unit is adopted to analyze the data packet, and the data packet cannot be processed from the 2 nd byte but is processed according to the condition that the read pointer is retreated to the 1 st byte, so that the integrity of the data packet is ensured, and the accuracy of data packet analysis is ensured.
In each embodiment of the present application, a communication channel in an initialization process includes a protocol determination unit and a necessary protocol processing unit, and then a protocol determination unit is added or maintained according to a protocol of a data packet and the determined protocol determination unit is deleted, so that a communication channel formed by one or more protocol processing units is finally obtained, and then it can be considered that the communication channel is completely constructed. The data flow in the communication channel can not change the protocol, thereby realizing the effects of dynamically adjusting the communication channel and improving the reusability of the port.
In the embodiment of the application, port multiplexing is performed based on a network protocol, for example, several different access protocols for the MQTT protocol, so that the specific access protocol used can be dynamically determined according to the characteristics of the required access protocol, and a corresponding channel processing model is established. For the protocol judging process, processing is carried out according to the characteristics of the protocol to be judged, for example, for several different access protocols of the MQTT protocol, two key characteristics of 'whether to use TLS' and 'whether to use WebSocket to establish connection' can be distinguished, and two protocol judging units are respectively used for judging; each protocol judging unit only needs to extract one byte in the channel data stream for judgment, so that the judging efficiency is very high, and the processing efficiency in the channel establishing process cannot be obviously influenced.
According to the embodiment of the application, when the channel is initially established, the specific protocol used is dynamically judged, and the corresponding protocol processing unit is added, so that the corresponding channel processing is established, once the channel processing is established, the data processing process in the subsequent communication channel does not need to be judged again, and therefore, the data processing efficiency of the subsequent process cannot be affected. Therefore, the method and the device realize that a single port simultaneously supports multiple access protocols, thereby increasing the convenience of access and better dealing with the condition of firewall port interception.
The present application further provides a non-transitory, readable storage medium, where one or more modules (programs) are stored, and when the one or more modules are applied to a device, the device may execute instructions (instructions) of method steps in this application.
Embodiments of the present application provide one or more machine-readable media having instructions stored thereon, which when executed by one or more processors, cause an electronic device to perform the methods as described in one or more of the above embodiments. In the embodiment of the application, the electronic device comprises an access server, a gateway, a sub-device and the like, wherein the sub-device is a device such as an internet of things device.
Embodiments of the present disclosure may be implemented as an apparatus, which may include servers (clusters), access servers, terminal devices such as IoT devices, and other electronic devices, using any suitable hardware, firmware, software, or any combination thereof, for a desired configuration. Fig. 10 schematically illustrates an example apparatus 1000 that may be used to implement various embodiments described herein.
For one embodiment, fig. 10 illustrates an example apparatus 1000 having one or more processors 1002, a control module (chipset) 1004 coupled to at least one of the processor(s) 1002, a memory 1006 coupled to the control module 1004, a non-volatile memory (NVM)/storage 1008 coupled to the control module 1004, one or more input/output devices 1010 coupled to the control module 1004, and a network interface 1012 coupled to the control module 1006.
The processor 1002 may include one or more single-core or multi-core processors, and the processor 1002 may include any combination of general-purpose or special-purpose processors (e.g., graphics processors, application processors, baseband processors, etc.). In some embodiments, the apparatus 1000 can be an apparatus such as the access server described in the embodiments of the present application.
In some embodiments, the apparatus 1000 may include one or more computer-readable media (e.g., the memory 1006 or the NVM/storage 1008) having instructions 1014 and one or more processors 1002 that, in conjunction with the one or more computer-readable media, are configured to execute the instructions 1014 to implement modules to perform the actions described in this disclosure.
For one embodiment, control module 1004 may include any suitable interface controllers to provide any suitable interface to at least one of the processor(s) 1002 and/or any suitable device or component in communication with control module 1004.
The control module 1004 may include a memory controller module to provide an interface to the memory 1006. The memory controller module may be a hardware module, a software module, and/or a firmware module.
Memory 1006 may be used, for example, to load and store data and/or instructions 1014 for device 1000. For one embodiment, memory 1006 may comprise any suitable volatile memory, such as suitable DRAM. In some embodiments, the memory 1006 may comprise a double data rate type four synchronous dynamic random access memory (DDR 4 SDRAM).
For one embodiment, the control module 1004 may include one or more input/output controllers to provide an interface to the NVM/storage 1008 and input/output device(s) 1010.
For example, NVM/storage 1008 may be used to store data and/or instructions 1014. NVM/storage 1008 may include any suitable non-volatile memory (e.g., flash memory) and/or may include any suitable non-volatile storage device(s) (e.g., one or more hard disk drive(s) (HDD (s)), one or more Compact Disc (CD) drive(s), and/or one or more Digital Versatile Disc (DVD) drive (s)).
The NVM/storage 1008 may include storage resources that are physically part of the device on which the apparatus 1000 is installed, or it may be accessible by the device and need not be part of the device. For example, NVM/storage 1008 may be accessed over a network via input/output device(s) 1010.
Input/output device(s) 1010 may provide an interface for apparatus 1000 to communicate with any other suitable device, input/output devices 1010 may include communication components, audio components, sensor components, and so forth. Network interface 1012 may provide an interface for device 1000 to communicate over one or more networks, and device 1000 may wirelessly communicate with one or more components of a wireless network according to any of one or more wireless network standards and/or protocols, such as to access a wireless network based on a communication standard, such as WiFi, 2G, 3G, 4G, etc., or a combination thereof.
For one embodiment, at least one of the processor(s) 1002 may be packaged together with logic for one or more controller(s) (e.g., memory controller module) of control module 1004. For one embodiment, at least one of the processor(s) 1002 may be packaged together with logic for one or more controller(s) of control module 1004 to form a System In Package (SiP). For one embodiment, at least one of the processor(s) 1002 may be integrated on the same die with the logic of one or more controllers of the control module 1004. For one embodiment, at least one of the processor(s) 1002 may be integrated on the same die with logic for one or more controller(s) of control module 1004 to form a system on chip (SoC).
In various embodiments, the apparatus 1000 may be, but is not limited to: a server, a desktop computing device, or a mobile computing device (e.g., a laptop computing device, a handheld computing device, a tablet, a netbook, etc.) among other terminal devices. In various embodiments, the apparatus 1000 may have more or fewer components and/or different architectures. For example, in some embodiments, device 1000 includes one or more cameras, a keyboard, a Liquid Crystal Display (LCD) screen (including a touch screen display), a non-volatile memory port, multiple antennas, a graphics chip, an Application Specific Integrated Circuit (ASIC), and speakers.
An embodiment of the present application provides a server, including: one or more processors; and one or more machine readable media having instructions stored thereon that, when executed by the one or more processors, cause the server to perform a data transmission method as described in one or more of the embodiments of the application.
For the device embodiment, since it is basically similar to the method embodiment, the description is simple, and for the relevant points, refer to the partial description of the method embodiment.
The embodiments in the present specification are described in a progressive manner, each embodiment focuses on differences from other embodiments, and the same and similar parts among the embodiments are referred to each other.
Embodiments of the present application are described with reference to flowchart illustrations and/or block diagrams of methods, terminal devices (systems), and computer program products according to embodiments of the application. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing terminal to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing terminal, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing terminal to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing terminal to cause a series of operational steps to be performed on the computer or other programmable terminal to produce a computer implemented process such that the instructions which execute on the computer or other programmable terminal provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
While preferred embodiments of the present application have been described, additional variations and modifications of these embodiments may occur to those skilled in the art once they learn of the basic inventive concepts. Therefore, it is intended that the appended claims be interpreted as including the preferred embodiment and all such alterations and modifications as fall within the true scope of the embodiments of the application.
Finally, it should also be noted that, herein, relational terms such as first and second, and the like may be used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Also, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or terminal that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or terminal. Without further limitation, an element defined by the phrases "comprising one of \ 8230; \8230;" does not exclude the presence of additional like elements in a process, method, article, or terminal device that comprises the element.
The data transmission method, the data transmission device, the server and the storage medium provided by the present application are described in detail above, and specific examples are applied in the present application to explain the principle and the implementation of the present application, and the description of the above embodiments is only used to help understand the method and the core idea of the present application; meanwhile, for a person skilled in the art, according to the idea of the present application, there may be variations in the specific embodiments and the application scope, and in summary, the content of the present specification should not be construed as a limitation to the present application.

Claims (16)

1. A method for data transmission, said method comprising:
after the communication channel is established and initialized, transmitting a data message in the communication channel;
selecting the processing unit of the communication channel according to the protocol of the data message to form the communication channel processed by the corresponding protocol, wherein the processing unit comprises: a protocol judging unit and a protocol processing unit; the protocol processing unit includes: a first protocol processing unit; the protocol judging unit is positioned in front of the first protocol processing unit in the communication channel;
analyzing the protocol of the data message by adopting the protocol judging unit;
and dynamically adding or maintaining a protocol processing unit required by the communication channel according to the analysis result, and removing the protocol judgment unit from the communication channel.
2. The method of claim 1, wherein analyzing the protocol of the data packet by using the protocol determining unit comprises:
the protocol judging unit reads data content from a target byte of the data message;
and judging the protocol of the data message according to the data content to generate a corresponding analysis result.
3. The method according to claim 1, wherein the dynamically adding the protocol processing unit required by the communication channel according to the analysis result comprises at least one of the following steps:
if the protocol of the data message is determined to be a second protocol, acquiring a second protocol processing unit, and adding the second protocol processing unit before a first protocol processing unit of the communication channel;
if the protocol of the data message is determined to be the third protocol, acquiring a third protocol processing unit, and adding the third protocol processing unit before the first protocol processing unit of the communication channel;
and if the protocol of the data message is determined to comprise the second protocol and the third protocol, acquiring a second protocol processing unit and a third protocol processing unit, and sequentially adding the second protocol processing unit and the third protocol processing unit before the first protocol processing unit of the communication channel.
4. The method of claim 1, wherein the protocol determination unit comprises: a first protocol judgment unit and a second protocol judgment unit; the protocol of the data message is analyzed by the protocol judging unit; dynamically adding or maintaining a protocol processing unit required by the communication channel according to an analysis result, and removing the protocol judgment unit from the communication channel, including:
reading data content from a target byte of the data message by using the first protocol judgment unit, and judging whether a protocol is a second protocol according to the data content;
if the protocol is not the second protocol, removing the first protocol judgment unit from the communication channel;
if the protocol is the second protocol, adding a second protocol processing unit before a second protocol judgment unit of the communication channel, and removing the first protocol judgment unit from the communication channel;
and processing the data message by adopting the second protocol processing unit to obtain processed message data.
5. The method of claim 4, wherein the selecting the processing unit of the communication channel according to the protocol of the datagram further comprises:
reading data content from a target byte of the data message by using the second protocol judgment unit, and judging whether a protocol is a third protocol according to the data content;
if the protocol is not the third protocol, removing the second protocol judgment unit from the communication channel;
if the protocol is the third protocol, adding a third protocol processing unit before the first protocol processing unit of the communication channel, and removing the second protocol judgment unit from the communication channel.
6. The method of claim 2, 4 or 5, further comprising:
recording position information corresponding to a read pointer in the data message;
after removing the protocol determination unit from the communication channel, the method further includes:
and recovering the position of a read pointer in the data message according to the position information.
7. The method according to any of claims 1-6, characterized in that it is applied in an access server based on the MQTT protocol for message queue telemetry transport.
8. A data transmission apparatus, said apparatus comprising:
the transmission module is used for transmitting the data message in the communication channel after the communication channel is established and initialized;
the processing unit selection module is used for selecting the processing unit of the communication channel according to the protocol of the data message to form the communication channel processed by the corresponding protocol; the processing unit includes: a protocol judging unit and a protocol processing unit; the protocol processing unit includes: a first protocol processing unit; the protocol judging unit is positioned in front of the first protocol processing unit in the communication channel;
the data processing module is used for processing the data message by adopting a processing unit in the communication channel processed by the protocol;
the processing unit selection module comprises:
the protocol judgment submodule is used for analyzing the protocol of the data message by adopting the protocol judgment unit;
and the unit selection submodule is used for dynamically adding or maintaining the protocol processing unit required by the communication channel according to the analysis result and removing the protocol judgment unit from the communication channel.
9. The apparatus of claim 8,
the protocol judgment submodule is used for reading data content from a target byte of the data message by adopting the protocol judgment unit; and judging the protocol of the data message according to the data content to generate a corresponding analysis result.
10. The apparatus of claim 8,
the unit selection submodule is used for acquiring a second protocol processing unit if the protocol of the data message is determined to be a second protocol, and adding the second protocol processing unit before the first protocol processing unit of the communication channel; if the protocol of the data message is determined to be the third protocol, acquiring a third protocol processing unit, and adding the third protocol processing unit before the first protocol processing unit of the communication channel; and if the protocol of the data message is determined to comprise the second protocol and the third protocol, acquiring a second protocol processing unit and a third protocol processing unit, and sequentially adding the second protocol processing unit and the third protocol processing unit before the first protocol processing unit of the communication channel.
11. The apparatus of claim 8, wherein the protocol determining unit comprises: a first protocol judgment unit and a second protocol judgment unit; the processing unit selection module comprises:
the first judging submodule is used for reading data content from a target byte of the data message by adopting the first protocol judging unit and judging whether a protocol is a second protocol according to the data content;
the unit processing submodule is used for removing the first protocol judging unit from the communication channel if the first protocol judging unit is not the second protocol; if the protocol is the second protocol, adding a second protocol processing unit before a second protocol judgment unit of the communication channel, and removing the first protocol judgment unit from the communication channel;
and the data processing module is used for processing the data message by adopting the second protocol processing unit to obtain processed message data.
12. The apparatus of claim 11, wherein the processing unit selection module further comprises:
a second judging submodule, configured to read data content from a target byte of the data packet by using the second protocol judging unit, and judge whether a protocol is a third protocol according to the data content;
the unit processing submodule is further configured to remove the second protocol determination unit from the communication channel if the second protocol determination unit is not the third protocol; if the protocol is the third protocol, adding a third protocol processing unit before the first protocol processing unit of the communication channel, and removing the second protocol judging unit from the communication channel.
13. The apparatus of claim 9 or 11 or 12,
the processing unit selection module is also used for recording the position information corresponding to the reading pointer in the data message; and after removing the protocol judgment unit from the communication channel, recovering the position of the read pointer in the data message according to the position information.
14. The apparatus according to any one of claims 8-13, wherein the apparatus is applied in an access server based on message queue telemetry transport MQTT protocol.
15. A server, comprising:
a processor; and
memory having stored thereon executable code which, when executed, causes the processor to perform a data transmission method as claimed in one or more of claims 1-7.
16. One or more machine-readable media having executable code stored thereon that, when executed, causes a processor to perform a method of data transmission as recited in one or more of claims 1-7.
CN201810997148.5A 2018-08-29 2018-08-29 Data transmission method, device, server and storage medium Active CN110875897B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201810997148.5A CN110875897B (en) 2018-08-29 2018-08-29 Data transmission method, device, server and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201810997148.5A CN110875897B (en) 2018-08-29 2018-08-29 Data transmission method, device, server and storage medium

Publications (2)

Publication Number Publication Date
CN110875897A CN110875897A (en) 2020-03-10
CN110875897B true CN110875897B (en) 2022-12-06

Family

ID=69714826

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201810997148.5A Active CN110875897B (en) 2018-08-29 2018-08-29 Data transmission method, device, server and storage medium

Country Status (1)

Country Link
CN (1) CN110875897B (en)

Families Citing this family (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
EP3979660B1 (en) 2020-08-03 2023-02-15 Wangsu Science & Technology Co., Ltd. Multi-protocol port sharing method and system, and server
CN114095588B (en) * 2020-08-03 2023-08-18 网宿科技股份有限公司 Sharing method, system and server of multi-protocol ports
CN113452759B (en) * 2021-06-07 2023-03-24 武汉市多比特信息科技有限公司 Method and device for sending and receiving websocket communication message
CN113507465B (en) * 2021-07-07 2022-09-09 赞同科技股份有限公司 socket and http shared port and message processing method and device thereof

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101426000A (en) * 2007-10-30 2009-05-06 北京启明星辰信息技术有限公司 General protocol parsing method and system
CN105162626A (en) * 2015-08-20 2015-12-16 西安工程大学 Network traffic depth identification system and method based on many-core processor
CN106453334A (en) * 2016-10-19 2017-02-22 北京悦畅科技有限公司 Communication protocol switching method, apparatus and system
CN106452833A (en) * 2016-08-30 2017-02-22 南京金水尚阳信息技术有限公司 Data transmission method for realizing RTU multi-protocol dynamic loading
CN107395639A (en) * 2017-08-29 2017-11-24 天津艾科仪科技有限公司 Intelligence obtains the method and system of video data in network

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US9781189B2 (en) * 2014-07-22 2017-10-03 Sap Se Managed device-to-device communication in business computing systems

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101426000A (en) * 2007-10-30 2009-05-06 北京启明星辰信息技术有限公司 General protocol parsing method and system
CN105162626A (en) * 2015-08-20 2015-12-16 西安工程大学 Network traffic depth identification system and method based on many-core processor
CN106452833A (en) * 2016-08-30 2017-02-22 南京金水尚阳信息技术有限公司 Data transmission method for realizing RTU multi-protocol dynamic loading
CN106453334A (en) * 2016-10-19 2017-02-22 北京悦畅科技有限公司 Communication protocol switching method, apparatus and system
CN107395639A (en) * 2017-08-29 2017-11-24 天津艾科仪科技有限公司 Intelligence obtains the method and system of video data in network

Also Published As

Publication number Publication date
CN110875897A (en) 2020-03-10

Similar Documents

Publication Publication Date Title
CN110875897B (en) Data transmission method, device, server and storage medium
US8874736B2 (en) Event extractor
RU2487484C2 (en) Stream media server, client terminal, method and system for downloading stream media
US11314763B2 (en) Off-chain functionality for data contained in blocks of blockchain
EP3718014A1 (en) Local interception traffic to a remote forward proxy
US9769012B2 (en) Notification normalization
US9331915B1 (en) Dynamic network traffic mirroring
GB2552220A (en) A method for detecting a live adaptive BIT rate stream
US9413560B2 (en) Differentiated quality of service using security as a service
WO2014048250A1 (en) Termininal interaction methods and related devices and systems
US20150058937A1 (en) Streaming video to cellular phones
US10623450B2 (en) Access to data on a remote device
US9363132B2 (en) Maximizing throughput of streaming media by simultaneously connecting to streaming media server over multiple independent network connections
WO2017101186A1 (en) Method for establishing wireless connection for application of user equipment
US20170171286A1 (en) Methods and devices for validating a video connection or other types of communication sessions over a computer network
WO2017096884A1 (en) Device identification method and device
US8271767B2 (en) Controlling arithmetic processing according to asynchronous and synchronous modes based upon data size threshold
CN111800423A (en) Method, system, computing device and medium for processing IP address
CN111314286A (en) Configuration method and device of security access control policy
EP3216189B1 (en) Delegation of intermediation on an encrypted data exchange
US10231004B2 (en) Network recording service
CN109495330B (en) Method and device for realizing UDP interception test
CN111049949B (en) Domain name identification method and device, electronic equipment and medium
US9319358B2 (en) Terminal interaction methods and related devices and systems
WO2015153723A1 (en) A method and system for real-time cloud storage of video content

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
REG Reference to a national code

Ref country code: HK

Ref legal event code: DE

Ref document number: 40025535

Country of ref document: HK

GR01 Patent grant
GR01 Patent grant