Message transmission method based on lightweight message transmission protocol and related device
By receiving the server's acknowledgement message after the message is transmitted, it solves the limitations of large resource consumption and message loss during message transmission in the prior art, and realizes the effect of reducing system consumption and improving message transmission reliability.
Patent Information
- Application Number
- CN202411640756.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-18
- Publication Date
- 2025-02-11
AI Technical Summary
The existing lightweight message transmission protocol has the limitations of large resource consumption and message loss during message transmission, especially when messages are lost, it requires more resources to be consumed for retransmission, resulting in large system consumption.
The system consumption is reduced by receiving a confirmation message sent by the server after the message is transmitted. The specific steps include generating messages to be sent, establishing communication connections, obtaining message priority information, encrypting and compressing the message, and sending the encrypted and compressed message according to the priority, and finally receiving the server's confirmation message.
It effectively reduces system consumption during information transmission, improves the reliability of message transmission, reduces the possibility of message loss, and improves the reliability of offline messages of terminal devices.
Smart Images

Figure CN119420748A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of data processing and information transmission, and in particular to a message transmission method and related devices based on a lightweight message transmission protocol. Background Art
[0002] In the message transmission method of the existing lightweight message transmission protocol, when transmitting a message, the message is usually transmitted directly, resulting in a large transmission consumption during the message transmission. At the same time, when transmitting a message, three message quality service levels are defined, namely QoS 0 (at most once delivery - the message may be lost and arrival is not guaranteed), QoS1 (at least once delivery - ensure that the message arrives at least once, but there may be duplications) and QoS2 (only once delivery - ensure that the message arrives only once, but it is more complicated to implement and requires more control messages). It can be seen that these three levels have certain limitations. When a message is lost, more resources are usually consumed for retransmission, resulting in a large system consumption during message transmission. Summary of the invention
[0003] The embodiment of the present application provides a message transmission method and related devices based on a lightweight message transmission protocol, which can determine whether the information is lost by receiving a confirmation message sent by a server after the message is transmitted, thereby greatly reducing system consumption during information transmission.
[0004] A first aspect of an embodiment of the present application provides a message transmission method based on a lightweight message transmission protocol, which is applied to a client, and the method includes:
[0005] Generate a message to be sent according to the extracted information to be sent;
[0006] Sending a connection message to the server, wherein the connection message instructs the server to establish a communication connection with the client;
[0007] If the communication connection with the server is successfully established, obtaining the priority information of the message to be sent;
[0008] Encrypting and compressing the message to be sent to obtain an encrypted and compressed message to be sent;
[0009] Sending the encrypted and compressed message to be sent to the server according to the priority information of the message to be sent;
[0010] A confirmation message sent by the server is received.
[0011] In this example, a message to be sent is generated based on the extracted information to be sent, and a connection message is sent to the server, wherein the connection message instructs the server to establish a communication connection with the client. If the communication connection with the server is successfully established, the priority information of the message to be sent is obtained, and the message to be sent is encrypted and compressed to obtain the encrypted and compressed message to be sent. The encrypted and compressed message to be sent is sent to the server according to the priority information of the message to be sent, and a confirmation message sent by the server is received. Therefore, after the message is transmitted, it is possible to determine whether the information is lost by receiving a confirmation message sent by the server, thereby greatly reducing system consumption during information transmission.
[0012] In a possible implementation, if the communication connection with the server fails to be established, the message to be sent is encrypted to obtain an encrypted message to be sent;
[0013] Compressing the encrypted message to be sent to obtain a compressed message to be sent;
[0014] The compressed message to be sent is stored.
[0015] In a possible implementation, after storing the compressed message to be sent, the method further includes:
[0016] Send a reconnection request to the server to instruct the server to establish a communication connection with the client;
[0017] If the communication connection with the server is successfully established, the compressed message to be sent is obtained from the memory;
[0018] Sending the compressed message to be sent to the server according to the priority information of the message to be sent;
[0019] A confirmation message sent by the server is received.
[0020] In a possible implementation, encrypting the message to be sent to obtain an encrypted message to be sent includes:
[0021] Obtaining a PIN code and generating a first random number;
[0022] Determine a first password verification value according to the PIN code and the first random number;
[0023] Extracting a value having the same number of bits as the first random number from the first password verification value to obtain a first value;
[0024] Determine a second password verification value according to the first value and the PIN code;
[0025] Repeat the above method of extracting the value having the same number of digits as the first random number from the first password verification value to obtain the first value, and determining the second password verification value according to the first value and the PIN code for k times to obtain the kth password verification value;
[0026] Extract the value having the same number of bits as the first random number from the kth password verification value to obtain the kth value;
[0027] Performing a hash operation on the k-th value to obtain a target hash value;
[0028] The target password verification value generated by the target hash value and the PIN code is used as a symmetric key for encrypting the identification key information, and the message to be sent is encrypted to obtain an encrypted message to be sent.
[0029] In a possible implementation, the method further includes:
[0030] Acquire network status information of the network where the terminal device and the server are located;
[0031] Determining a reconnection frequency according to the network status information;
[0032] Reconnection is performed using the reconnection frequency.
[0033] A second aspect of an embodiment of the present application provides a message transmission device based on a lightweight message transmission protocol, which is applied to a client, and the device includes:
[0034] A generating unit, used for generating a message to be sent according to the extracted information to be sent;
[0035] A first sending unit, configured to send a connection message to the server, wherein the connection message instructs the server to establish a communication connection with the client;
[0036] an acquiring unit, configured to acquire the priority information of the message to be sent if the communication connection with the server is successfully established;
[0037] An encryption unit, used to encrypt and compress the message to be sent to obtain an encrypted and compressed message to be sent;
[0038] A second sending unit, configured to send the encrypted and compressed message to be sent to the server according to the priority information of the message to be sent;
[0039] A receiving unit is used to receive a confirmation message sent by the server.
[0040] In a possible implementation, the device is further used for:
[0041] If the communication connection with the server fails to be established, encrypting the message to be sent to obtain an encrypted message to be sent;
[0042] Compressing the encrypted message to be sent to obtain a compressed message to be sent;
[0043] The compressed message to be sent is stored.
[0044] In a possible implementation, after storing the compressed message to be sent, the apparatus is further configured to:
[0045] Send a reconnection request to the server to instruct the server to establish a communication connection with the client;
[0046] If the communication connection with the server is successfully established, the compressed message to be sent is obtained from the memory;
[0047] Sending the compressed message to be sent to the server according to the priority information of the message to be sent;
[0048] A confirmation message sent by the server is received.
[0049] In a possible implementation, in the aspect of encrypting the message to be sent to obtain the encrypted message to be sent, the apparatus is further configured to:
[0050] Obtaining a PIN code and generating a first random number;
[0051] Determine a first password verification value according to the PIN code and the first random number;
[0052] Extracting a value having the same number of bits as the first random number from the first password verification value to obtain a first value;
[0053] Determine a second password verification value according to the first value and the PIN code;
[0054] Repeat the above method of extracting the value having the same number of digits as the first random number from the first password verification value to obtain the first value, and determining the second password verification value according to the first value and the PIN code for k times to obtain the kth password verification value;
[0055] Extract the value having the same number of bits as the first random number from the kth password verification value to obtain the kth value;
[0056] Performing a hash operation on the k-th value to obtain a target hash value;
[0057] The target password verification value generated by the target hash value and the PIN code is used as a symmetric key for encrypting the identification key information, and the message to be sent is encrypted to obtain an encrypted message to be sent.
[0058] In a possible implementation, the device is further used for:
[0059] Acquire network status information of the network where the terminal device and the server are located;
[0060] Determining a reconnection frequency according to the network status information;
[0061] Reconnection is performed using the reconnection frequency.
[0062] A third aspect of an embodiment of the present application provides a terminal, comprising a processor, an input device, an output device and a memory, wherein the processor, input device, output device and memory are interconnected, wherein the memory is used to store a computer program, the computer program comprises program instructions, and the processor is configured to call the program instructions to execute the step instructions in the first aspect of the embodiment of the present application.
[0063] The fourth aspect of the embodiments of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program for electronic data exchange, wherein the computer program enables a computer to execute part or all of the steps described in the first aspect of the embodiments of the present application.
[0064] A fifth aspect of the embodiments of the present application provides a computer program product, wherein the computer program product includes a non-transitory computer-readable storage medium storing a computer program, and the computer program is operable to cause a computer to execute some or all of the steps described in the first aspect of the embodiments of the present application. The computer program product may be a software installation package. BRIEF DESCRIPTION OF THE DRAWINGS
[0065] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0066] Figure 1 A structural diagram of an Internet of Things system is provided for an embodiment of the present application;
[0067] Figure 2 A flowchart of a message transmission device method based on a lightweight message transmission protocol is provided for an embodiment of the present application;
[0068] Figure 3 A schematic diagram of the structure of a terminal provided in an embodiment of the present application;
[0069] Figure 4 A structural schematic diagram of a message transmission device based on a lightweight message transmission protocol is provided for an embodiment of the present application. DETAILED DESCRIPTION
[0070] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0071] The terms "first", "second", etc. in the specification and claims of this application and the above-mentioned drawings are used to distinguish different objects, rather than to describe a specific order. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device that includes a series of steps or units is not limited to the listed steps or units, but optionally includes steps or units that are not listed, or optionally includes other steps or units inherent to these processes, methods, products or devices.
[0072] Reference to "embodiments" in this application means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present application. The appearance of the phrase in various locations in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described in this application may be combined with other embodiments.
[0073] In order to better understand the message transmission method based on the lightweight message transmission protocol provided by the embodiment of the present application, the existing lightweight message transmission protocol is briefly introduced below. In the lightweight message transmission protocol (MQTT, Message Queuing Telemetry Transport), three message quality service levels are defined, namely QoS 0 (at most once delivery - the message may be lost and arrival is not guaranteed), QoS1 (at least once delivery - ensure that the message arrives at least once, but there may be duplicates) and QoS2 (only once delivery - ensure that the message arrives only once, but it is more complicated to implement and requires more control messages). It can be seen that these three levels have certain limitations and cannot perfectly solve the problem of message loss.
[0074] The MQTT broker can be configured to maintain the session, which means that even if the client is offline, the broker will retain the message until the client reconnects. If the broker is not configured with session persistence, or the session persistence time is set to a short time, messages sent during the device offline period may be lost.
[0075] Messages can also be lost due to the way the client is implemented. If the client does not properly handle message acknowledgments before disconnecting, or does not request undelivered messages when reconnecting, then these messages may be lost.
[0076] The MQTT protocol allows messages to set expiration times (through the Payload Format Indicator field). If messages expire while the device is offline, they will not be sent even if the device comes back online.
[0077] In order to solve the above technical problems, the present application provides a message transmission method based on a lightweight message transmission protocol, which can determine whether the information is lost by receiving a confirmation message sent by the server after the message is transmitted, thereby greatly reducing the system consumption during information transmission. At the same time, when the connection fails, the message is encrypted and compressed and stored. When reconnecting, the encrypted and compressed message is transmitted, thereby improving the reliability of offline messages on terminal devices and reducing the possibility of message loss.
[0078] The message transmission method based on lightweight message transmission protocol is applied to the Internet of Things system. Figure 1 A schematic diagram of the structure of an Internet of Things system is shown. Figure 1 As shown, the Internet of Things system includes: a client 2 and a server 1, wherein information is transmitted between the client 2 and the server 1 through a lightweight message transmission protocol, the client 2 extracts the information to be sent to generate a message to be sent, and the client 2 sends a connection message to the server. If the communication connection between the client 2 and the server is successfully established, the client 2 obtains the priority information of the message to be sent, and the client 2 encrypts and compresses the message to be sent to obtain the encrypted and compressed message to be sent. The client 2 sends the encrypted and compressed message to be sent to the server 1 according to the priority information of the message to be sent. After receiving the encrypted and compressed message to be sent, the server 1 sends a confirmation message to the client. Therefore, after the message is transmitted, the client can determine whether the information is lost by receiving the confirmation message sent by the server, thereby greatly reducing the system consumption during information transmission.
[0079] See also Figure 2 , Figure 2The embodiment of the present application provides an interactive intention of a message transmission method based on a lightweight message transmission protocol. Figure 2 As shown, the method is applied to an Internet of Things system, and the method includes:
[0080] 201. The client generates a message to be sent according to the extracted information to be sent.
[0081] Among them, both the server and the client can support lightweight message transmission protocols. The message to be sent can be any message that needs to be sent. The client can be, for example, an IoT client, a sensor, etc. Messages can be transmitted between the client and the server. After the client transmits the message to the server, the server can perform subsequent processing on the received message, such as data analysis, data display, etc. It can be constructed using a general method for constructing messages to be sent, which will not be repeated here.
[0082] 202. The client sends a connection message to the server, where the connection message instructs the server to establish a communication connection with the client.
[0083] The link message may be a message used in a general lightweight message transmission protocol to establish a communication connection.
[0084] 203. If the communication connection with the server is successfully established, the client obtains the priority information of the message to be sent.
[0085] The priority information of the message to be sent can be understood as information used to characterize the order in which the messages to be sent are sent. Different priorities correspond to different sending orders. For example, the first priority can represent the highest level of sending priority, and the sending priority can make the corresponding message to be sent immediately after the current message is sent. Of course, there are also second priority, third priority, etc. Different priorities correspond to different sending methods. You can refer to the existing priority sending methods to send messages.
[0086] 204. The client encrypts and compresses the message to be sent to obtain an encrypted and compressed message to be sent.
[0087] When the client encrypts the message to be sent, it may use a symmetric encryption method to perform encryption processing. After the encryption processing is completed, the encrypted message to be sent is compressed to obtain an encrypted and compressed message to be sent.
[0088] 205. The client sends the encrypted and compressed message to be sent to the server according to the priority information of the message to be sent.
[0089] The client determines the sending time of the message to be sent according to the priority information, and sends the encrypted and compressed message to be sent to the server at the sending time.
[0090] 206. After receiving the encrypted and compressed message to be sent, the server generates a confirmation message.
[0091] After receiving the encrypted and compressed message to be sent, the server stores the encrypted and compressed message to be sent. The server also generates a confirmation message, which is used to indicate that the server has received the encrypted and compressed message to be sent, so that the server and the client can synchronize whether the message is correctly received and transmitted, etc., which improves the reliability of message transmission.
[0092] 207. The server sends a confirmation message to the client.
[0093] After generating the confirmation message, the server sends a confirmation message to the client at the next message sending time.
[0094] 208. The client receives a confirmation message sent by the server.
[0095] After receiving the confirmation message sent by the server, the client confirms that the server has received the corresponding message to be sent.
[0096] In this example, a message to be sent is generated based on the extracted information to be sent, and a connection message is sent to the server, wherein the connection message instructs the server to establish a communication connection with the client. If the communication connection with the server is successfully established, the priority information of the message to be sent is obtained, and the message to be sent is encrypted and compressed to obtain the encrypted and compressed message to be sent. The encrypted and compressed message to be sent is sent to the server according to the priority information of the message to be sent, and a confirmation message sent by the server is received. Therefore, after the message is transmitted, it is possible to determine whether the information is lost by receiving a confirmation message sent by the server, thereby greatly reducing system consumption during information transmission.
[0097] In a possible implementation, in an existing lightweight message transmission protocol, if the client does not correctly process message confirmation before disconnecting, or does not request undelivered messages when reconnecting, these messages may be lost, making it impossible to retransmit messages, etc., which reduces the reliability of message transmission. Therefore, the embodiment of the present application also provides the following method to solve the above problem, specifically:
[0098] A1. If the communication connection with the server fails to be established, the client encrypts the message to be sent to obtain an encrypted message to be sent;
[0099] A2. The client compresses the encrypted message to be sent to obtain a compressed message to be sent;
[0100] A3. The client stores the compressed message to be sent.
[0101] The message to be sent can be encrypted to obtain the encrypted message to be sent. When encrypting, a symmetric encryption method can be used for encryption, specifically, a symmetric key for symmetric encryption is generated by a PIN code and a random code, and finally the symmetric key is used for encryption to obtain the encrypted message to be sent.
[0102] The above method can solve the problem of message loss in the existing MQTT when the terminal device is offline, making the reliability of message transmission higher. At the same time, if the message to be sent is retransmitted after the terminal device is online again, if it still cannot be retransmitted successfully, the stored message to be sent can be cleared, and the client's system memory usage can be reduced to improve reliability.
[0103] In a possible implementation, after the client is back online, a reconnection request may be initiated to the server for reconnection, specifically, after storing the compressed message to be sent, the method further includes:
[0104] B1. The client sends a reconnection request to the server to instruct the server to establish a communication connection with the client;
[0105] B2. If the communication connection with the server is successfully established, the client obtains the compressed message to be sent from the memory;
[0106] B3. The client sends the compressed message to be sent to the server according to the priority information of the message to be sent;
[0107] B4. The client receives the confirmation message sent by the server.
[0108] The above steps B3 and B4 may refer to the specific implementation methods of the corresponding steps in the above embodiments, which will not be repeated here.
[0109] After the client comes back online, it sends a reconnection request to the server to instruct the client to establish a communication connection with the server.
[0110] In a possible implementation, a method for encrypting the message to be sent to obtain an encrypted message to be sent includes:
[0111] C1. The client obtains a PIN code and generates a first random number;
[0112] C2. The client determines a first password verification value according to the PIN code and the first random number;
[0113] C3. The client extracts a value having the same number of digits as the first random number from the first password verification value to obtain a first value;
[0114] C4. The client determines a second password verification value according to the first value and the PIN code;
[0115] C5. The client repeats the above method k times of extracting the value with the same number of digits as the first random number from the first password verification value to obtain the first value, and determining the second password verification value according to the first value and the PIN code to obtain the kth password verification value;
[0116] C6. The client extracts the value that is the same as the first random number from the kth password verification value to obtain the kth value;
[0117] C7. The client performs a hash operation on the k-th value to obtain a target hash value;
[0118] C8. The client uses the target password verification value generated by the target hash value and the PIN code as a symmetric key for encrypting the identification key information, encrypts the message to be sent, and obtains an encrypted message to be sent.
[0119] The PIN code can be obtained by a common acquisition method, and the first random number can be generated. The method by which the client determines the first password verification value according to the PIN code and the first random number can be to use a common password verification value to obtain the first password verification value.
[0120] A value can be randomly extracted from the first password check value according to the number of digits of the first random number to obtain the first value. Random extraction can be understood as the first digit value of the first value is randomly determined, and then the value of the continuous digits of the first random number is extracted to obtain the first value. The number of digits of the first value can be 8 digits, and the number of digits of the first password check value is 16 digits.
[0121] K can be set by empirical value or historical data, for example, it can be 50, 80, etc. The method of generating the target password value from the number of digits of the target hash value and the PIN code can be the same as the method of generating the password value in the above embodiment.
[0122] The symmetric key generated by the above method can have a higher security, thereby improving the security of subsequent encryption processing.
[0123] In a possible implementation, a reconnection frequency may be determined according to the network status information, and reconnection may be performed according to the reconnection frequency to adapt to the network status and improve the stability of the system, specifically:
[0124] D1. The client obtains network status information of the network where the terminal device and the server are located;
[0125] D2. The client determines the reconnection frequency according to the network status information;
[0126] D3. The client reconnects using the reconnection frequency.
[0127] A general network status information acquisition method can be used to obtain the network status information. Different network statuses can have corresponding reconnection frequencies. Specifically, the reconnection frequency corresponding to the current network status information can be determined according to the corresponding relationship table between network status information and reconnection frequency. Finally, the reconnection frequency is used to reconnect, so the network status can be matched and the stability of the system can be improved.
[0128] In a specific embodiment, the message transmission method based on the lightweight message transmission protocol can also be defined as the MQTT-NEXT protocol, which also supports the following functions:
[0129] Multi-path routing: Supports multi-path routing. When one path is unavailable, it automatically switches to an alternative path to improve the reliability of message transmission.
[0130] Cross-platform compatibility: Ensure that the message transmission method of the MQTT-NEXT protocol can run on different operating systems and hardware platforms, improving its versatility.
[0131] Simplified API design: Provides a simple and intuitive API to facilitate developers to quickly integrate and use the MQTT-NEXT protocol.
[0132] Scalability: The design takes into account possible changes in future requirements, making the protocol highly scalable and convenient for adding new features and functions.
[0133] Detailed Logging: Record detailed communication logs to facilitate problem tracking and performance optimization.
[0134] Community and documentation support: Establish an active community and provide detailed documentation to help developers better understand and use MQTT-NEXT.
[0135] For the above embodiments, please refer to Figure 3 , Figure 3A schematic diagram of the structure of a terminal provided in an embodiment of the present application, as shown in the figure, includes a processor, an input device, an output device and a memory, the processor, the input device, the output device and the memory are interconnected, wherein the memory is used to store a computer program, the computer program includes program instructions, the processor is configured to call the program instructions, and the program includes instructions for executing the following steps;
[0136] Generate a message to be sent according to the extracted information to be sent;
[0137] Sending a connection message to the server, wherein the connection message instructs the server to establish a communication connection with the client;
[0138] If the communication connection with the server is successfully established, obtaining the priority information of the message to be sent;
[0139] Encrypting and compressing the message to be sent to obtain an encrypted and compressed message to be sent;
[0140] Sending the encrypted and compressed message to be sent to the server according to the priority information of the message to be sent;
[0141] A confirmation message sent by the server is received.
[0142] The above mainly introduces the scheme of the embodiment of the present application from the perspective of the execution process on the method side. It is understandable that in order to realize the above functions, the terminal includes a hardware structure and / or software module corresponding to the execution of each function. Those skilled in the art should easily realize that, in combination with the units and algorithm steps of each example described in the embodiments provided herein, the present application can be implemented in the form of hardware or a combination of hardware and computer software. Whether a function is executed in the form of hardware or computer software driving hardware depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.
[0143] The embodiment of the present application can divide the terminal into functional units according to the above method example. For example, each functional unit can be divided according to each function, or two or more functions can be integrated into one processing unit. The above integrated unit can be implemented in the form of hardware or in the form of software functional units. It should be noted that the division of units in the embodiment of the present application is schematic and is only a logical function division. There may be other division methods in actual implementation.
[0144] In line with the above, see Figure 4 , Figure 4The present invention provides a schematic diagram of a message transmission device based on a lightweight message transmission protocol. Figure 4 As shown, applied to a client, the device includes:
[0145] A generating unit 401, configured to generate a message to be sent according to the extracted information to be sent;
[0146] A first sending unit 402 is used to send a connection message to the server, where the connection message instructs the server to establish a communication connection with the client;
[0147] The acquisition unit 403 is used to acquire the priority information of the message to be sent if the communication connection with the server is successfully established;
[0148] The encryption unit 404 is used to encrypt and compress the message to be sent to obtain an encrypted and compressed message to be sent;
[0149] The second sending unit 405 is used to send the encrypted and compressed message to be sent to the server according to the priority information of the message to be sent;
[0150] The receiving unit 406 is configured to receive a confirmation message sent by the server.
[0151] In a possible implementation, the device is further used for:
[0152] If the communication connection with the server fails to be established, encrypting the message to be sent to obtain an encrypted message to be sent;
[0153] Compressing the encrypted message to be sent to obtain a compressed message to be sent;
[0154] The compressed message to be sent is stored.
[0155] In a possible implementation, after storing the compressed message to be sent, the apparatus is further configured to:
[0156] Send a reconnection request to the server to instruct the server to establish a communication connection with the client;
[0157] If the communication connection with the server is successfully established, the compressed message to be sent is obtained from the memory;
[0158] Sending the compressed message to be sent to the server according to the priority information of the message to be sent;
[0159] A confirmation message sent by the server is received.
[0160] In a possible implementation, in the aspect of encrypting the message to be sent to obtain the encrypted message to be sent, the apparatus is further configured to:
[0161] Obtaining a PIN code and generating a first random number;
[0162] Determine a first password verification value according to the PIN code and the first random number;
[0163] Extracting a value having the same number of bits as the first random number from the first password verification value to obtain a first value;
[0164] Determine a second password verification value according to the first value and the PIN code;
[0165] Repeat the above method of extracting the value having the same number of digits as the first random number from the first password verification value to obtain the first value, and determining the second password verification value according to the first value and the PIN code for k times to obtain the kth password verification value;
[0166] Extract the value having the same number of bits as the first random number from the kth password verification value to obtain the kth value;
[0167] Performing a hash operation on the k-th value to obtain a target hash value;
[0168] The target password verification value generated by the target hash value and the PIN code is used as a symmetric key for encrypting the identification key information, and the message to be sent is encrypted to obtain an encrypted message to be sent.
[0169] In a possible implementation, the device is further used for:
[0170] Acquire network status information of the network where the terminal device and the server are located;
[0171] Determining a reconnection frequency according to the network status information;
[0172] Reconnection is performed using the reconnection frequency.
[0173] An embodiment of the present application also provides a computer storage medium, wherein the computer storage medium stores a computer program for electronic data exchange, and the computer program enables a computer to execute part or all of the steps of any message transmission method based on a lightweight message transmission protocol as recorded in the above method embodiments.
[0174] An embodiment of the present application also provides a computer program product, which includes a non-transitory computer-readable storage medium storing a computer program, and the computer program enables a computer to execute part or all of the steps of any message transmission method based on a lightweight message transmission protocol as recorded in the above method embodiments.
[0175] It should be noted that, for the aforementioned method embodiments, for the sake of simplicity, they are all expressed as a series of action combinations, but those skilled in the art should be aware that the present application is not limited by the described order of actions, because according to the present application, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily required by the present application.
[0176] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0177] In the several embodiments provided in the present application, it should be understood that the disclosed device can be implemented in other ways. For example, the device embodiments described above are only schematic, such as the division of the units, which is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, and the indirect coupling or communication connection of the device or unit can be electrical or other forms.
[0178] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0179] In addition, the functional units in the various embodiments of the application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated units may be implemented in the form of hardware or in the form of software program modules.
[0180] If the integrated unit is implemented in the form of a software program module and sold or used as an independent product, it can be stored in a computer-readable memory. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a memory, including a number of instructions to enable a computer device (which can be a personal computer, server or network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned memory includes: U disk, read-only memory (ROM), random access memory (RAM), mobile hard disk, disk or optical disk and other media that can store program codes.
[0181] A person of ordinary skill in the art can understand that all or part of the steps in the various methods of the above embodiments can be completed by instructing related hardware through a program, and the program can be stored in a computer-readable memory, which can include: a flash drive, a read-only memory, a random access memory, a magnetic disk or an optical disk, etc.
[0182] The embodiments of the present application are introduced in detail above. Specific examples are used in this article to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method and core idea of the present application. At the same time, for general technical personnel in this field, according to the idea of the present application, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.
Claims
1. A message transmission method based on a lightweight message transmission protocol, characterized in that: Applied to a client, the method comprises: Generate a message to be sent according to the extracted information to be sent; Sending a connection message to the server, wherein the connection message instructs the server to establish a communication connection with the client; If the communication connection with the server is successfully established, obtaining the priority information of the message to be sent; Encrypting and compressing the message to be sent to obtain an encrypted and compressed message to be sent; Sending the encrypted and compressed message to be sent to the server according to the priority information of the message to be sent; Receive a confirmation message sent by the server.
2. The message transmission method based on a lightweight message transmission protocol according to claim 1, characterized in that: If the communication connection with the server fails to be established, encrypting the message to be sent to obtain an encrypted message to be sent; Compressing the encrypted message to be sent to obtain a compressed message to be sent; The compressed message to be sent is stored.
3. The message transmission method based on the lightweight message transmission protocol according to claim 2 is characterized in that: After storing the compressed message to be sent, the method further includes: Send a reconnection request to the server to instruct the server to establish a communication connection with the client; If the communication connection with the server is successfully established, the compressed message to be sent is obtained from the memory; Sending the compressed message to be sent to the server according to the priority information of the message to be sent; A confirmation message sent by the server is received.
4. The message transmission method based on a lightweight message transmission protocol according to claim 2, characterized in that: The step of encrypting the message to be sent to obtain an encrypted message to be sent includes: Obtaining a PIN code and generating a first random number; Determine a first password verification value according to the PIN code and the first random number; Extracting a value having the same number of bits as the first random number from the first password verification value to obtain a first value; Determine a second password verification value according to the first value and the PIN code; Repeat the above method of extracting the value having the same number of digits as the first random number from the first password verification value to obtain the first value, and determining the second password verification value according to the first value and the PIN code for k times to obtain the kth password verification value; Extract the value having the same number of bits as the first random number from the kth password verification value to obtain the kth value; Performing a hash operation on the k-th value to obtain a target hash value; The target password verification value generated by the target hash value and the PIN code is used as a symmetric key for encrypting the identification key information, and the message to be sent is encrypted to obtain an encrypted message to be sent.
5. The message transmission method based on a lightweight message transmission protocol according to claim 3 or 4, characterized in that: The method further comprises: Acquire network status information of the network where the terminal device and the server are located; Determining a reconnection frequency according to the network status information; Reconnection is performed using the reconnection frequency.
6. A message transmission device based on a lightweight message transmission protocol, characterized in that: Applied to a client, the device comprises: A generating unit, used for generating a message to be sent according to the extracted information to be sent; A first sending unit, configured to send a connection message to the server, wherein the connection message instructs the server to establish a communication connection with the client; an acquiring unit, configured to acquire the priority information of the message to be sent if the communication connection with the server is successfully established; An encryption unit, used to encrypt and compress the message to be sent to obtain an encrypted and compressed message to be sent; A second sending unit, configured to send the encrypted and compressed message to be sent to the server according to the priority information of the message to be sent; A receiving unit is used to receive a confirmation message sent by the server.
7. The message transmission device based on the lightweight message transmission protocol according to claim 6, characterized in that: The device is also used for: If the communication connection with the server fails to be established, encrypting the message to be sent to obtain an encrypted message to be sent; Compressing the encrypted message to be sent to obtain a compressed message to be sent; The compressed message to be sent is stored.
8. The message transmission method based on the lightweight message transmission protocol according to claim 7 is characterized in that: After storing the compressed message to be sent, the device is further used for: Send a reconnection request to the server to instruct the server to establish a communication connection with the client; If the communication connection with the server is successfully established, the compressed message to be sent is obtained from the memory; Sending the compressed message to be sent to the server according to the priority information of the message to be sent; A confirmation message sent by the server is received.
9. A terminal, characterized in that: It includes a processor, an input device, an output device and a memory, which are interconnected, wherein the memory is used to store a computer program, the computer program includes program instructions, and the processor is configured to call the program instructions to execute the message transmission method based on the lightweight message transmission protocol as described in any one of claims 1 to 5.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, wherein the computer program includes program instructions, and when the program instructions are executed by a processor, the processor executes the message transmission method based on a lightweight message transmission protocol as described in any one of claims 1 to 5.