Heartbeat cycle detection method and device, electronic equipment and storage medium

By adjusting the detection method of the heartbeat cycle and optimizing the step size and start period using heartbeat failure records, the problem of the terminal's instability in heartbeat cycle settings was solved, achieving a stable heartbeat state for the client in different network environments, reducing the number of retries, and improving processing efficiency.

CN115941562BActive Publication Date: 2025-12-12SHENZHEN COOCAA NETWORK TECH CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202211242287.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-10-11
Publication Date
2025-12-12
Estimated Expiration
2042-10-11

AI Technical Summary

Technical Problem

In existing technologies, some terminals cannot reach a stable state during the heartbeat cycle setting process, resulting in frequent reconnections and retries, which increases the terminal's processing workload.

Method used

By acquiring the initial heartbeat parameters, the maximum heartbeat period is probed upwards using the initial heartbeat period and step size. If the maximum heartbeat period is not detected, the initial heartbeat parameters are reset to obtain the target heartbeat parameters. The step size and initial period are adjusted using the heartbeat failure record, and the maximum heartbeat period is probed again until a stable state is reached.

Benefits of technology

This enables the client to maintain a stable heartbeat state under different network environments, reducing the number of retries and improving processing efficiency and stability.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115941562B_ABST
    Figure CN115941562B_ABST
Patent Text Reader

Abstract

The application discloses a heartbeat period detection method and device, electronic equipment and storage medium, and belongs to the technical field of communication. The method comprises the following steps: obtaining initial heartbeat parameters, wherein the initial heartbeat parameters comprise a first starting heartbeat period, a first step length and a first maximum heartbeat period; the first starting heartbeat period and the first step length are used to detect the first maximum heartbeat period upwards; if the first maximum heartbeat period is not detected, the initial heartbeat parameters are reset to obtain target heartbeat parameters, wherein the target heartbeat parameters comprise a second starting heartbeat period, a second step length and a second maximum heartbeat period; and the target heartbeat parameters are used to continue detecting the second maximum heartbeat period upwards. Through the application, the technical problem that part of terminals cannot reach a stable state in a heartbeat detection process in the related art is solved.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of communication, in particular to a heartbeat period detection method and device, electronic equipment and storage medium. BACKGROUND

[0002] The general heartbeat period setting method is that an engineering personnel directly specifies a certain heartbeat period value as the maximum heartbeat period according to experience, whether the setting is performed by a person on a terminal one by one or by a network when a terminal logs in for the first time. After a client terminal establishes a connection with a server, the terminal sends a heartbeat packet to the background according to the fixed maximum heartbeat period, and confirms the availability of the connection through the sending of the heartbeat packet.

[0003] In the related art, the server can only issue a maximum heartbeat period to most terminals, and some terminals cannot reach the preset maximum heartbeat period, so repeated reconnection and repeated retries are required to try to reach a stable state, thereby increasing the processing workload of the terminal.

[0004] At present, there is no effective solution to the above problems in the related art. SUMMARY

[0005] The present application provides a heartbeat period detection method and device, electronic equipment and storage medium to solve the technical problem that some terminals cannot reach a stable state in the heartbeat detection process in the related art.

[0006] According to an aspect of an embodiment of the present application, a heartbeat period detection method is provided, including: obtaining initial heartbeat parameters, wherein the initial heartbeat parameters include a first starting heartbeat period, a first step length and a first maximum heartbeat period; detecting the first maximum heartbeat period upward using the first starting heartbeat period and the first step length; if the first maximum heartbeat period is not detected, resetting the initial heartbeat parameters to obtain target heartbeat parameters, wherein the target heartbeat parameters include a second starting heartbeat period, a second step length and a second maximum heartbeat period; and continuing to detect the second maximum heartbeat period upward using the target heartbeat parameters.

[0007] Further, resetting the initial heartbeat parameters to obtain target heartbeat parameters includes: resetting the first maximum heartbeat period to obtain a second maximum heartbeat period using an intermediate value between a current failed heartbeat period and a last successful heartbeat period; resetting the first starting heartbeat period to obtain a second starting heartbeat period; and resetting the first step length according to the second maximum heartbeat period and the second starting heartbeat period to obtain a second step length.

[0008] Further, resetting the first maximum heartbeat period by using an intermediate value between the current failed heartbeat period and the last successful heartbeat period to obtain a second maximum heartbeat period comprises: resetting the first maximum heartbeat period by using the current failed heartbeat period, the last successful heartbeat period and the following preset formula to obtain the second maximum heartbeat period: max=(cur+cur-step) / 2; wherein, max is the second maximum heartbeat period, cur is the current failed heartbeat period, step is the first step, and cur-step is the last successful heartbeat period.

[0009] Further, resetting the first step by using the second maximum heartbeat period and the second starting heartbeat period to obtain a second step comprises: calculating a difference value between the second maximum heartbeat period and the second starting heartbeat period; resetting the first step as Nth part of the difference value to obtain the second step, wherein N is a natural number greater than 0.

[0010] Further, continuing to detect the second maximum heartbeat period by using the target heartbeat parameter comprises: sending a heartbeat data packet to the server by using the second starting heartbeat period; if a heartbeat acknowledgement packet in response to the server is received, continuing to detect the heartbeat by increasing the heartbeat period by the second step until the heartbeat period after the increase reaches the second maximum heartbeat period; and determining the second maximum heartbeat period as the target heartbeat period.

[0011] Further, obtaining an initial heartbeat parameter comprises: detecting whether there is a cached pre-stored maximum heartbeat period; if there is a cached pre-stored maximum heartbeat period, setting a first starting heartbeat period according to the pre-stored maximum heartbeat period, wherein the first starting heartbeat period is greater than a preset minimum heartbeat period and smaller than the pre-stored maximum heartbeat period; and if there is no cached pre-stored maximum heartbeat period, setting the first starting heartbeat period as the preset minimum heartbeat period.

[0012] Further, after continuing to detect the second maximum heartbeat period by using the target heartbeat parameter, the method comprises: if the second maximum heartbeat period is detected, sending a heartbeat data packet to the server by using the second maximum heartbeat period; and if a heartbeat acknowledgement packet in response to the server is not received, verifying a network channel of the server by using the first starting heartbeat period.

[0013] According to another aspect of the embodiments of the present application, a heartbeat period detection device is also provided, comprising: an acquisition module, configured to acquire initial heartbeat parameters, wherein the initial heartbeat parameters comprise a first starting heartbeat period, a first step length and a first maximum heartbeat period; a first detection module, configured to detect the first maximum heartbeat period upwardly using the first starting heartbeat period and the first step length; a reset module, configured to reset the initial heartbeat parameters to obtain target heartbeat parameters if the first maximum heartbeat period is not detected, wherein the target heartbeat parameters comprise a second starting heartbeat period, a second step length and a second maximum heartbeat period; and a second detection module, configured to continue detecting the second maximum heartbeat period upwardly using the target heartbeat parameters.

[0014] Further, the reset module comprises a reset unit, configured to reset the first maximum heartbeat period to obtain the second maximum heartbeat period using an intermediate value between a current failed heartbeat period and a last successful heartbeat period; reset the first starting heartbeat period to obtain the second starting heartbeat period; and reset the first step length according to the second maximum heartbeat period and the second starting heartbeat period to obtain the second step length.

[0015] Further, the reset unit comprises a first reset sub-unit, configured to calculate the second maximum heartbeat period using the current failed heartbeat period, the last successful heartbeat period and the following preset formula: max=(cur+cur-step) / 2; wherein max is the second maximum heartbeat period, cur is the current failed heartbeat period, step is the first step length, and cur-step is the last successful heartbeat period.

[0016] Further, the reset unit comprises a second reset sub-unit, configured to calculate a difference value between the second maximum heartbeat period and the second starting heartbeat period; and reset the first step length to be one Nth of the difference value to obtain the second step length, wherein N is a natural number greater than 0.

[0017] Further, the second detection module is further configured to send a heartbeat data packet to a server using the second starting heartbeat period; if a heartbeat acknowledgement packet in response to the heartbeat data packet is received, continue heartbeat detection after the heartbeat period is adjusted upwardly using the second step length until the adjusted heartbeat period reaches the second maximum heartbeat period; and determine the second maximum heartbeat period as the target heartbeat period.

[0018] Further, the obtaining module comprises an obtaining submodule, configured to detect whether there is a cached pre-stored maximum heartbeat period; if there is a cached pre-stored maximum heartbeat period, set a first starting heartbeat period according to the pre-stored maximum heartbeat period, wherein the first starting heartbeat period is greater than a preset minimum heartbeat period and smaller than the pre-stored maximum heartbeat period; if there is no cached pre-stored maximum heartbeat period, set the first starting heartbeat period as the preset minimum heartbeat period.

[0019] Further, the heartbeat period detecting device comprises a third detecting module, configured to, if a second maximum heartbeat period is detected, send a heartbeat data packet to the server using the second maximum heartbeat period; and if a heartbeat acknowledgement packet in response to the heartbeat data packet is not received from the server, verify the network channel of the server using the first starting heartbeat period.

[0020] According to another aspect of the embodiments of the present application, a storage medium is also provided, which comprises a stored program, and the program performs the steps described above when running.

[0021] According to another aspect of the embodiments of the present application, an electronic device is also provided, which comprises a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory complete mutual communication through the communication bus; the memory is configured to store a computer program; and the processor is configured to execute the steps in the above method by running the program stored in the memory.

[0022] The embodiments of the present application also provide a computer program product comprising instructions which, when executed on a computer, cause the computer to perform the steps in the above method.

[0023] According to the present application, an initial heartbeat parameter is obtained, wherein the initial heartbeat parameter comprises a first starting heartbeat period, a first step length and a first maximum heartbeat period; the first starting heartbeat period and the first step length are used to detect the first maximum heartbeat period upwards; if the first maximum heartbeat period is not detected, the initial heartbeat parameter is reset to obtain a target heartbeat parameter, wherein the target heartbeat parameter comprises a second starting heartbeat period, a second step length and a second maximum heartbeat period; the target heartbeat parameter is used to continue detecting the second maximum heartbeat period upwards; in the process of searching for a preset maximum heartbeat period, a new maximum heartbeat period is redefined through the record of heartbeat failure, so that the client can reach a stable heartbeat state which conforms to the current network condition. BRIEF DESCRIPTION OF DRAWINGS

[0024] The accompanying drawings, which are included to provide a further understanding of the application and are incorporated in and constitute a part of this application, illustrate embodiments of the application and serve to explain the principles of the application, and do not limit the application in any inproper manner. In the drawings:

[0025] Figure 1 is a hardware structure block diagram of a computer according to an embodiment of the present application;

[0026] Figure 2 is a flow chart of a heartbeat period detection method according to an embodiment of the present application;

[0027] Figure 3 is a flow chart of a heartbeat period detection method according to an embodiment of the present application;

[0028] Figure 4 is a structure block diagram of a heartbeat period detection device according to an embodiment of the present application. DETAILED DESCRIPTION

[0029] In order to enable persons skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be described clearly and completely below with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, but not all the embodiments of the present application. Based on the embodiments in the present application, all other embodiments obtained by persons skilled in the art without creative work should fall within the protection scope of the present application. It should be noted that, in the case of no conflict, the embodiments in the present application and the features in the embodiments can be combined with each other.

[0030] It should be noted that the terms "first", "second", and the like in the specification and claims of the present application and the above-described drawings are used to distinguish similar objects, and do not necessarily indicate a specific order or a chronological sequence. It should be understood that the data thus used can be interchanged under appropriate circumstances, so that the embodiments of the present application described herein can be implemented in an order other than that illustrated or described herein. In addition, the terms "include" and "have" and any variations thereof are intended to cover non-exclusive inclusion, for example, a process, method, product, or device that includes a series of steps or units does not necessarily have to be limited to the clearly listed steps or units, but can include other steps or units that are not clearly listed or inherent to the process, method, product, or device.

[0031] Embodiment 1

[0032] The method embodiments provided in the embodiments of the present application can be executed in a mobile phone, a computer, a tablet, or similar computing devices. Taking the case of running on a computer, Figure 1 is a hardware structure block diagram of a computer according to an embodiment of the present application. As shown in Figure 1 , the computer can include one or more (CPU) 1001, memory 1002, storage 1003, and input and output interface 1004. Figure 1The computer shown in FIG. 1 includes only one processor 102 (the processor 102 can include, but is not limited to, a processing device such as a microprocessor MCU or a programmable logic device FPGA), and a memory 104 for storing data. Optionally, the computer can further include a transmission device 106 for communication functions, and an input / output device 108. Those skilled in the art can understand that, Figure 1 The structure shown in FIG. 1 is only illustrative, and does not limit the structure of the computer. For example, the computer can include more or fewer components than those shown in FIG. 1, or have a different configuration than that shown in FIG. 1. Figure 1 For example, the computer can include more or fewer components than those shown in FIG. 1, or have a different configuration than that shown in FIG. 1. Figure 1 For example, the computer can include more or fewer components than those shown in FIG. 1, or have a different configuration than that shown in FIG. 1.

[0033] The memory 104 can be used to store computer programs, such as software programs of application software and modules, such as a computer program corresponding to a video motion and stillness recognition method in an embodiment of the present application. The processor 102 executes various functional applications and data processing by running the computer programs stored in the memory 104, that is, implements the method described above. The memory 104 can include a high-speed random access memory, and can further include a non-volatile memory, such as one or more magnetic storage devices, a flash memory, or other non-volatile solid-state memories. In some examples, the memory 104 can further include a memory remotely arranged with respect to the processor 102, and these remote memories can be connected to the computer through a network. Examples of the network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and a combination thereof.

[0034] The transmission device 106 is used to receive or send data via a network. Specific examples of the network can include a wireless network provided by a communication provider of the computer. In one example, the transmission device 106 includes a network adapter (NIC), which can be connected to other network devices through a base station so as to communicate with the Internet. In one example, the transmission device 106 can be a radio frequency (RF) module, which is used to communicate with the Internet in a wireless manner.

[0035] In the present embodiment, a heartbeat period detection method is provided, Figure 2 is a flowchart of a heartbeat period detection method according to an embodiment of the present application, as shown in FIG. 2, the flow includes the following steps: Figure 2

[0036] Step S10, obtaining an initial heartbeat parameter, wherein the initial heartbeat parameter includes a first starting heartbeat period, a first step size, and a first maximum heartbeat period;

[0037] ​Step S20: Use the first initial heartbeat cycle and the first step length upward to detect the first maximum heartbeat cycle;

[0038] The client establishes a TCP (Transmission Control Protocol) connection with the server, synchronizes with the server, and sets initial heartbeat parameters. These initial heartbeat parameters include a first starting heartbeat period, a first step length, and a first maximum heartbeat period. The first starting heartbeat period and the first step length are used to probe upwards towards the first maximum heartbeat period. The first starting heartbeat period, the first step length, and the first maximum heartbeat period can all be preset values. Probing upwards towards the first maximum heartbeat period using the first starting heartbeat period and the first step length can be done as follows: a heartbeat data packet is sent to the server using the first starting heartbeat period; if a heartbeat acknowledgment packet is received from the server, the heartbeat period is increased by the first step length, and heartbeat probing continues until the increased heartbeat period reaches the first maximum heartbeat period. The first maximum heartbeat period is then determined as the target heartbeat period. For example... Figure 3 As shown: 1. Start; 2. Establish a TCP connection with the server; 3. Synchronize and set information such as heartbeat cycle, for example, set the first initial heartbeat cycle to 30 seconds, the first step length to 30 seconds, and the first maximum heartbeat cycle to 20 minutes; 4. ... Figure 3 5. If a heartbeat confirmation packet is received from the server, the heartbeat is successful. 6. The current heartbeat period is adjusted by adding the first step length of 30 seconds to the first initial heartbeat period of 30 seconds, resulting in an adjusted heartbeat step length of 60 seconds. Heartbeat data packets are then sent to the server at intervals of 60 seconds to continue heartbeat detection. 7. The success of the heartbeat is determined. 8. If the heartbeat is successful, the maximum heartbeat period is further determined. In this example, the current heartbeat period of 60 seconds has not reached the first maximum heartbeat period of 20 minutes. Therefore, the process returns to step 6 and continues to adjust the heartbeat period by the first step length to continue heartbeat detection. 9. The process continues until the adjusted heartbeat period reaches the first maximum heartbeat period of 20 minutes. If so, the first maximum heartbeat period of 20 minutes is considered the optimal target heartbeat period.

[0039] Step S30: If the first maximum heartbeat cycle is not detected, reset the initial heartbeat parameters to obtain the target heartbeat parameters, wherein the target heartbeat parameters include the second starting heartbeat cycle, the second step size, and the second maximum heartbeat cycle;

[0040] Step S40: Continue to probe the second maximum heartbeat cycle upwards using the target heartbeat parameters.

[0041] In the embodiment, if the first maximum heartbeat period is not detected in the process of increasing the heartbeat period, the client terminal can not reach the maximum heartbeat period due to the influence of the network environment in which the client terminal is located. In the conventional method, the client terminal repeatedly detects the first maximum heartbeat period by using the first start heartbeat period and the first step, thereby increasing the processing workload of the client terminal and reducing the processing efficiency, and it is difficult to meet the heartbeat stability of some client terminals.

[0042] In the embodiment, if the first maximum heartbeat period is not detected, the initial heartbeat parameter is reset to obtain a target heartbeat parameter, wherein the target heartbeat parameter includes a second start heartbeat period, a second step and a second maximum heartbeat period. The second maximum heartbeat period is continuously detected by using the target heartbeat parameter. In the process of finding the preset maximum heartbeat period, a new maximum heartbeat period is redefined through the record of heartbeat failure, so that the client terminal can reach a stable heartbeat state that meets the current network condition.

[0043] The initial heartbeat parameter is obtained, wherein the initial heartbeat parameter includes a first start heartbeat period, a first step and a first maximum heartbeat period. The first maximum heartbeat period is detected by using the first start heartbeat period and the first step. If the first maximum heartbeat period is not detected, the initial heartbeat parameter is reset to obtain a target heartbeat parameter, wherein the target heartbeat parameter includes a second start heartbeat period, a second step and a second maximum heartbeat period. The second maximum heartbeat period is continuously detected by using the target heartbeat parameter. In the process of finding the preset maximum heartbeat period, a new maximum heartbeat period is redefined through the record of heartbeat failure, so that the client terminal can reach a stable heartbeat state that meets the current network condition.

[0044] In an embodiment of the present embodiment, resetting the initial heartbeat parameter to obtain a target heartbeat parameter includes:

[0045] In step S301, the first maximum heartbeat period is reset by using the intermediate value between the current failed heartbeat period and the last successful heartbeat period to obtain a second maximum heartbeat period.

[0046] In step S302, the second start heartbeat period is reset by using the first start heartbeat period.

[0047] In step S303, the first step is reset according to the second maximum heartbeat period and the second start heartbeat period to obtain a second step.

[0048] If the first maximum heartbeat period is not detected, that is, the heartbeat fails when the current heartbeat period is increased, the initial heartbeat parameter is reset to obtain a target heartbeat parameter. For details, please refer to Figure 3 , Figure 3In step 6, the current heartbeat period is increased by the first step length of 30 seconds on the basis of the first starting heartbeat period of 30 seconds, to obtain an increased heartbeat step length of 60 seconds, and then a heartbeat data packet is sent to the server at a time interval of the increased heartbeat step length of 60 seconds for heartbeat detection; 7, it is judged whether the heartbeat is successful; if the heartbeat fails, step 14 is executed, and the current heartbeat period and other information are reset. In the embodiment, the process of resetting the initial heartbeat parameters (the first starting heartbeat period, the first step length and the first maximum heartbeat period) is as follows: the first maximum heartbeat period is reset by using the intermediate value between the current failed heartbeat period and the last successful heartbeat period, to obtain a second maximum heartbeat period; the new maximum heartbeat is redefined by the record of the last successful and failed heartbeat, so that a stable state most suitable for the current network condition can be found through one or several retries, for example, the current heartbeat period is 120s after being increased by the first step length, the current heartbeat period fails, and the last successful heartbeat period is 90s, so that the second maximum heartbeat period is the intermediate value between 90s and 120s;

[0049] The first starting heartbeat period is reset by resetting the current heartbeat period after being increased by the first step length as the first starting heartbeat period, to obtain a second starting heartbeat period, for example, the current heartbeat period is 120s, and the first starting heartbeat period is 30s, so that the second starting heartbeat period is 30s;

[0050] The first step length is reset according to the second maximum heartbeat period and the current failed heartbeat period, to obtain a second step length. The target heartbeat parameters obtained after the reset are used to continue to detect the second maximum heartbeat period, which can solve the technical problem that the maximum value cannot be reached on some terminals due to terminal network environment problems, and repeated retries and reconnections are caused, so that the best stable state cannot be reached.

[0051] Further, the first maximum heartbeat period is reset by using the intermediate value between the current failed heartbeat period and the last successful heartbeat period, to obtain a second maximum heartbeat period.

[0052] Step A, the second maximum heartbeat period is calculated by using the current failed heartbeat period, the last successful heartbeat period and the following preset formula:

[0053] Step B, max=(cur+cur-step) / 2; wherein, the max is the second maximum heartbeat period, the cur is the current failed heartbeat period, the step is the first step length, and the cur-step is the last successful heartbeat period.

[0054] Specifically, the second maximum heartbeat period can be calculated by using the current failed heartbeat period, the last successful heartbeat period and the following preset formula:

[0055] The preset formula is: max=(cur+cur-step) / 2, wherein max is the second maximum heartbeat period, cur is the current failed heartbeat period, step is the first step length, and cur-step is the last successful heartbeat period. For example, the current heartbeat period is 120s after being increased by the first step length, the current heartbeat period 120s fails, and the last successful heartbeat period is 90s. The second maximum heartbeat period can be 105s, which is the middle value of 90s to 120s.

[0056] Further, resetting the first step length according to the second maximum heartbeat period and the second starting heartbeat period to obtain a second step length comprises:

[0057] Step C, calculating a difference between the second maximum heartbeat period and the second starting heartbeat period;

[0058] Step D, resetting the first step length to Nth of the difference to obtain a second step length, wherein N is a natural number greater than 0.

[0059] The calculation method of resetting the second step length at each heartbeat failure is as follows: calculating a difference between the second maximum heartbeat period and the second starting heartbeat period, and resetting the first step length to Nth of the difference to obtain a second step length, wherein N is a natural number greater than 0. The second step length can be obtained by the preset step length calculation formula: step=(max-cur) / N, wherein step is the second step length, max is the second maximum heartbeat period, cur is the second starting heartbeat period, and N is a natural number greater than 0. In an example, N is 4. It should be noted that if the calculated second step length is less than the preset minimum step length, the second step length is the minimum step length, that is, if step

[0060] In the embodiment, continuing to detect the second maximum heartbeat period by using the target heartbeat parameter comprises:

[0061] Step S401, sending a heartbeat data packet to a server by using the second starting heartbeat period;

[0062] Step S402: If a heartbeat confirmation packet is received from the server, the heartbeat period is increased by the second step size and the heartbeat detection continues until the increased heartbeat period reaches the second maximum heartbeat period.

[0063] Step S403: Determine the second maximum heartbeat cycle as the target heartbeat cycle.

[0064] A heartbeat data packet is sent to the server using the second initial heartbeat cycle. If a heartbeat confirmation packet is received from the server, the heartbeat cycle is increased by the second step size, and heartbeat detection continues until the increased heartbeat cycle reaches the second maximum heartbeat cycle. The second maximum heartbeat cycle is then determined as the target heartbeat cycle. Figure 3 As shown, step 14 resets the current heartbeat cycle and other information, i.e., resets the initial heartbeat parameters. After obtaining the target heartbeat parameters, it returns to step 4 until the adjusted heartbeat cycle reaches the second maximum heartbeat cycle, and then determines the second maximum heartbeat cycle as the target heartbeat cycle. Determining whether the adjusted heartbeat cycle reaches the second maximum heartbeat cycle includes: checking if the adjusted heartbeat cycle is greater than or equal to the difference between the second maximum heartbeat cycle and the preset minimum step size; alternatively, it can be directly determined whether the adjusted heartbeat cycle is greater than or equal to the second maximum heartbeat cycle. Adjusting the maximum heartbeat cycle based on the client's network environment solves the problem that the server can only issue an optimal heartbeat cycle for most clients, but cannot guarantee that it is optimal for every client.

[0065] In another embodiment of this example, obtaining the initial heartbeat parameters includes:

[0066] Step S101: Detect whether there is a cached maximum heartbeat cycle;

[0067] Step S102: If there is a cached maximum heartbeat period, set a first starting heartbeat period according to the cached maximum heartbeat period. The first starting heartbeat period is greater than the preset maximum heartbeat period and less than the cached maximum heartbeat period.

[0068] Step S103: If there is no cached maximum heartbeat period, then set the first starting heartbeat period to the preset maximum heartbeat period.

[0069] In the embodiment, the initial heartbeat parameter can be a preset fixed value, or can be calculated according to specific conditions. It is detected whether there is a pre-stored maximum heartbeat period in the cache. If there is a pre-stored maximum heartbeat period in the cache, it indicates that the client has reached an optimal state in the process of the last running. At this time, the first starting heartbeat period is set according to the pre-stored maximum heartbeat period. The first starting heartbeat period is set to a value greater than the preset minimum heartbeat period and less than the pre-stored maximum heartbeat period. Specifically, in an example, in the case where there is a pre-stored maximum heartbeat period, the first starting heartbeat period takes a value of cur1 = local / 2, where cur1 is the first starting heartbeat period, and local is the pre-stored maximum heartbeat period, that is, the current starting heartbeat takes 1 / 2 of the optimal heartbeat period, and does not need to start from a smaller starting heartbeat to detect, so that the maximum heartbeat period can be quickly reached. If there is no pre-stored maximum heartbeat period in the cache, the first starting heartbeat period is set to the preset minimum heartbeat period. There is no cache data, and the initial heartbeat uses the preset minimum heartbeat period, for example, 30s.

[0070] In the embodiment, after the target heartbeat parameter is used to continue to detect the second maximum heartbeat period, the method comprises:

[0071] Step E, if the second maximum heartbeat period is detected, the second maximum heartbeat period is used to send a heartbeat data packet to the server;

[0072] Step F, if the server response heartbeat confirmation packet is not received, the first starting heartbeat period is used to verify the network channel of the server.

[0073] In the embodiment, after the second maximum heartbeat period is detected, the second maximum heartbeat period is used to send a heartbeat data packet to the server. If the server response heartbeat confirmation packet is not received, it indicates that the heartbeat fails, and the first starting heartbeat period is used to verify the network channel of the server. For details, refer to Figure 3 , Figure 3 In the embodiment, the optimal heartbeat period is the second maximum heartbeat period in the embodiment. The second maximum heartbeat period is used to send a heartbeat. If the heartbeat is sent successfully, the second maximum heartbeat period is continuously used to send a heartbeat. If the heartbeat fails, the second maximum heartbeat period is unchanged, the first starting heartbeat period is used to re-heartbeat to re-detect the second maximum heartbeat period to retry the network channel of the server, that is, returning to execute step 4. If the first starting heartbeat period fails to send a heartbeat, it indicates that the current network channel is abnormal, and needs to be reconnected, so as to return to step 2 to re-establish a TCP connection with the server. If the first starting heartbeat period fails to send a heartbeat, the second maximum heartbeat period is continuously detected.

[0074] Those skilled in the art can clearly understand that the method according to the above-mentioned embodiments can be realized by means of software and necessary general hardware platforms, and of course, can also be realized by hardware, but in many cases, the former is a better implementation. Based on such understanding, the technical solutions of the present application can be embodied in the form of software products, and the computer software products are stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), and include a plurality of instructions for making a terminal device (which can be a mobile phone, computer, server, or network device, etc.) execute the method described in various embodiments of the present application.

[0075] Embodiment 2

[0076] In this embodiment, a heartbeat period detection device is also provided for implementing the above-mentioned embodiments and preferred embodiments, which have been described and will not be repeated. As used below, the term "module" can be a combination of software and / or hardware that implements a predetermined function. Although the device described in the following embodiments is preferably implemented in software, implementation of hardware, or a combination of software and hardware, is also possible and contemplated.

[0077] Figure 4 is a structural block diagram of a heartbeat period detection device according to an embodiment of the present application, as shown in Figure 4 The device includes an acquisition module 60, a first detection module 61, a reset module 62, and a second detection module 63, wherein,

[0078] The acquisition module 60 is configured to acquire initial heartbeat parameters, wherein the initial heartbeat parameters include a first starting heartbeat period, a first step size, and a first maximum heartbeat period.

[0079] The first detection module 61 is configured to detect the first maximum heartbeat period upwardly using the first starting heartbeat period and the first step size.

[0080] The reset module 62 is configured to reset the initial heartbeat parameters to obtain target heartbeat parameters if the first maximum heartbeat period is not detected, wherein the target heartbeat parameters include a second starting heartbeat period, a second step size, and a second maximum heartbeat period.

[0081] The second detection module 63 is configured to continue detecting the second maximum heartbeat period upwardly using the target heartbeat parameters.

[0082] Optionally, the reset module includes a reset unit, used to reset the first maximum heartbeat cycle using the intermediate value between the current failed heartbeat cycle and the previous successful heartbeat cycle to obtain a second maximum heartbeat cycle; reset using the first starting heartbeat cycle to obtain a second starting heartbeat cycle; and reset the first step length according to the second maximum heartbeat cycle and the second starting heartbeat cycle to obtain a second step length.

[0083] Optionally, the reset unit includes a first reset subunit, used to calculate the second maximum heartbeat period using the current failed heartbeat period, the previous successful heartbeat period, and the following preset formula: max=(cur+cur-step) / 2; where max is the second maximum heartbeat period, cur is the current failed heartbeat period, step is the first step length, and cur-step is the previous successful heartbeat period.

[0084] Optionally, the reset unit includes a second reset subunit, used to calculate the difference between the second maximum heartbeat cycle and the second initial heartbeat cycle; and reset the first step length to one-N of the difference to obtain the second step length, where N is a natural number greater than 0.

[0085] Optionally, the second detection module is further configured to send a heartbeat data packet to the server using the second initial heartbeat period; if a heartbeat confirmation packet is received from the server, the heartbeat period is increased using the second step size and the heartbeat detection continues until the increased heartbeat period reaches the second maximum heartbeat period; and the second maximum heartbeat period is determined as the target heartbeat period.

[0086] Optionally, the acquisition module includes an acquisition submodule, used to detect whether there is a cached pre-stored maximum heartbeat period; if there is a cached pre-stored maximum heartbeat period, a first starting heartbeat period is set according to the pre-stored maximum heartbeat period, wherein the first starting heartbeat period is greater than a preset maximum heartbeat period and less than the pre-stored maximum heartbeat period; if there is no cached pre-stored maximum heartbeat period, the first starting heartbeat period is set to the preset maximum heartbeat period.

[0087] Optionally, the heartbeat cycle detection device includes a third detection module, used to send a heartbeat data packet to the server using the second maximum heartbeat cycle if a second maximum heartbeat cycle is detected; and to verify the server's network channel using the first initial heartbeat cycle if no heartbeat confirmation packet is received from the server.

[0088] It should be noted that the above modules can be implemented by software or hardware. For the latter, they can be implemented in the following ways, but are not limited to: all the above modules are located in the same processor; or, the above modules are located in different processors in any combination.

[0089] Embodiment 3

[0090] The embodiment of the present application also provides a storage medium, wherein the storage medium stores a computer program, and the computer program is arranged to execute the steps in any of the method embodiments when running.

[0091] Optionally, in the embodiment, the storage medium is arranged to store a computer program for executing the following steps:

[0092] S1, acquiring initial heartbeat parameters, wherein the initial heartbeat parameters comprise a first starting heartbeat period, a first step length and a first maximum heartbeat period;

[0093] S2, detecting the first maximum heartbeat period upwardly by using the first starting heartbeat period and the first step length;

[0094] S3, resetting the initial heartbeat parameters to obtain target heartbeat parameters if the first maximum heartbeat period is not detected, wherein the target heartbeat parameters comprise a second starting heartbeat period, a second step length and a second maximum heartbeat period;

[0095] S4, continuing to detect the second maximum heartbeat period upwardly by using the target heartbeat parameters.

[0096] Optionally, in the embodiment, the storage medium can include but is not limited to a U disk, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk or an optical disk and various storage media that can store a computer program.

[0097] The embodiment of the present application also provides an electronic device, comprising a memory and a processor, wherein the memory stores a computer program, and the processor is arranged to execute the computer program to execute the steps in any of the method embodiments.

[0098] Optionally, the electronic device can further comprise a transmission device and an input and output device, wherein the transmission device is connected with the processor, and the input and output device is connected with the processor.

[0099] Optionally, in the embodiment, the processor can be arranged to execute the following steps by the computer program:

[0100] S1, acquiring initial heartbeat parameters, wherein the initial heartbeat parameters comprise a first starting heartbeat period, a first step length and a first maximum heartbeat period;

[0101] S2, detecting the first maximum heartbeat period upwardly using the first starting heartbeat period and the first step length;

[0102] S3, resetting the initial heartbeat parameter to obtain a target heartbeat parameter if the first maximum heartbeat period is not detected, wherein the target heartbeat parameter comprises a second starting heartbeat period, a second step length and a second maximum heartbeat period;

[0103] S4, continuing to detect the second maximum heartbeat period upwardly using the target heartbeat parameter.

[0104] Optionally, specific examples in the embodiments can refer to the examples described in the above embodiments and optional implementation manners, and the embodiments will not be described here again.

[0105] The sequence numbers of the above-described embodiments of the present application are only for description, and do not represent the advantages or disadvantages of the embodiments.

[0106] In the above-described embodiments of the present application, the description of each embodiment has its own focus, and the parts not described in detail in a certain embodiment can be referred to the relevant description of other embodiments.

[0107] In the several embodiments provided by the present application, it should be understood that the disclosed technology can be implemented in other ways. Of course, the unit embodiment described above is only schematic. For example, the division of the units is only a logical function division. There can be another division manner for actual implementation, for example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the displayed or discussed mutual couplings or direct couplings or communication connections between the units can be indirect couplings or communication connections through some interfaces, units or modules, and can be electrical or other forms.

[0108] The units described as separate components can or can not be physically separate, and the components displayed as units can or can not be physical units, that is, they can be located in one place, or can be distributed on multiple network units. According to actual needs, some or all of the units can be selected to achieve the purpose of the embodiments.

[0109] In addition, each functional unit in each embodiment of the present application can be integrated in one processing unit, or each unit can exist physically, or two or more units can be integrated in one unit. The above integrated unit can be realized in the form of hardware, or in the form of software functional unit.

[0110] The integrated unit, if implemented in the form of a software function unit and sold or used as an independent product, can be stored in a computer readable storage medium. Based on such understanding, the technical solutions of the present application essentially or say the part that contributes to the prior art or the whole or part of the technical solutions can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes a plurality of instructions for causing a computer device (which can be a personal computer, a server or a network device, etc.) to execute all or part of the steps of the method described in the various embodiments of the present application. The aforementioned storage medium includes: a U disk, a read-only memory (ROM, Read-Only Memory), a random access memory (RAM, Random Access Memory), a mobile hard disk, a magnetic disk or an optical disk, and various media that can store program codes.

[0111] The above is only the preferred embodiment of the present application, and it should be pointed out that for those skilled in the art, without departing from the principles of the present application, a number of improvements and refinements can be made, which should be considered as the protection scope of the present application.

Claims

1. A method of detecting a heart beat cycle, characterized by, The method comprises: obtaining initial heartbeat parameters, wherein the initial heartbeat parameters comprise a first starting heartbeat period, a first step length and a first maximum heartbeat period; detecting the first maximum heartbeat period upwardly using the first starting heartbeat period and the first step length; if the first maximum heartbeat period is not detected, resetting the initial heartbeat parameters to obtain target heartbeat parameters, wherein the target heartbeat parameters comprise a second starting heartbeat period, a second step length and a second maximum heartbeat period; continuing to detect the second maximum heartbeat period upwardly using the target heartbeat parameters; wherein the resetting the initial heartbeat parameters to obtain target heartbeat parameters comprises: resetting the first maximum heartbeat period to obtain the second maximum heartbeat period using an intermediate value between a current failed heartbeat period and a last successful heartbeat period; resetting the first starting heartbeat period to obtain the second starting heartbeat period; resetting the first step length to obtain the second step length according to the second maximum heartbeat period and the second starting heartbeat period; the resetting the first maximum heartbeat period to obtain the second maximum heartbeat period using an intermediate value between a current failed heartbeat period and a last successful heartbeat period comprises: calculating the second maximum heartbeat period using the current failed heartbeat period, the last successful heartbeat period and the following preset formula: max = (cur + cur-step) / 2; wherein max is the second maximum heartbeat period, cur is the current failed heartbeat period, step is the first step length, and cur-step is the last successful heartbeat period.

2. The method of claim 1, wherein, the resetting the first step length to obtain the second step length according to the second maximum heartbeat period and the second starting heartbeat period comprises: calculating a difference value between the second maximum heartbeat period and the second starting heartbeat period; resetting the first step length to the Nth part of the difference value to obtain the second step length, wherein N is a natural number greater than 0.

3. The method of claim 1, wherein, the continuing to detect the second maximum heartbeat period upwardly using the target heartbeat parameters comprises: sending a heartbeat data packet to a server using the second starting heartbeat period; if a heartbeat acknowledgement packet in response to the server is received, continuing to detect the heartbeat upwardly after adjusting the heartbeat period using the second step length until the adjusted heartbeat period reaches the second maximum heartbeat period; determining the second maximum heartbeat period as a target heartbeat period.

4. The method of claim 1, wherein, obtaining initial heartbeat parameters comprises: detecting whether there is a cached pre-stored maximum heartbeat period; if there is a cached pre-stored maximum heartbeat period, setting the first starting heartbeat period according to the pre-stored maximum heartbeat period, wherein the first starting heartbeat period is greater than a preset minimum heartbeat period and smaller than the pre-stored maximum heartbeat period; if there is no cached pre-stored maximum heartbeat period, setting the first starting heartbeat period as the preset minimum heartbeat period.

5. The method of claim 1, wherein, after the continuing to detect the second maximum heartbeat period upwardly using the target heartbeat parameters, the method comprises: if the second maximum heartbeat period is detected, sending a heartbeat data packet to a server using the second maximum heartbeat period; If the heartbeat acknowledgement packet of the server response is not received, a network channel of the server is verified using the first starting heartbeat period.

6. A heartbeat cycle detection apparatus, characterized by comprising: The method comprises the following steps: An acquisition module is configured to acquire initial heartbeat parameters, wherein the initial heartbeat parameters comprise a first starting heartbeat period, a first step length, and a first maximum heartbeat period. A first detection module is configured to detect the first maximum heartbeat period upward using the first starting heartbeat period and the first step length. A reset module is configured to reset the initial heartbeat parameters to obtain target heartbeat parameters if the first maximum heartbeat period is not detected, wherein the target heartbeat parameters comprise a second starting heartbeat period, a second step length, and a second maximum heartbeat period. A second detection module is configured to continue detecting the second maximum heartbeat period upward using the target heartbeat parameters. The reset module is configured to reset the first maximum heartbeat period to obtain the second maximum heartbeat period using an intermediate value between a current failed heartbeat period and a last successful heartbeat period. The first starting heartbeat period is reset to obtain the second starting heartbeat period. The first step length is reset to obtain the second step length according to the second maximum heartbeat period and the second starting heartbeat period. The reset module is configured to reset the first maximum heartbeat period to obtain the second maximum heartbeat period using an intermediate value between a current failed heartbeat period and a last successful heartbeat period. The reset module is configured to reset the first maximum heartbeat period to obtain the second maximum heartbeat period using a preset formula. The preset formula is as follows: max = (cur + cur-step) / 2; wherein max is the second maximum heartbeat period, cur is the current failed heartbeat period, step is the first step length, and cur-step is the last successful heartbeat period. The method comprises a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory communicate with each other through the communication bus.

7. An electronic device, comprising: The memory is configured to store a computer program. The processor is configured to execute the method steps of any one of claims 1 to 5 by running the program stored in the memory. The storage medium comprises a stored program, wherein the program runs to execute the method steps of any one of claims 1 to 5.

8. A storage medium, characterized by The storage medium comprises a stored program, wherein the program runs to execute the method steps of any one of claims 1 to 5.

Citation Information

Patent Citations

  • Communication method and device and computer readable storage medium

    CN111698098A