Heartbeat interval adjusting method and device, electronic equipment and storage medium
By dynamically adjusting the interval of heartbeat packets sent by the client on the server, the problem of inaccurate heartbeat interval settings in different network environments is solved, and more efficient bandwidth utilization and more stable connections are achieved.
Patent Information
- Application Number
- CN202311007277.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-08-10
- Publication Date
- 2025-02-18
AI Technical Summary
In different network environments, it is difficult to accurately set the heartbeat interval of the client sends heartbeat packets to the server, resulting in wasted bandwidth or disconnection of the connection.
After receiving the heartbeat packet sent by the client on the server, adjust it based on the status information carried by the heartbeat packet, dynamically determine the target heartbeat interval, and return the reply packet to the client, so that the client can send the new heartbeat interval according to the new heartbeat interval. A heartbeat packet.
Improves the accuracy of heartbeat interval settings, is suitable for different network environments, reduces bandwidth waste and resource consumption, while simplifying client logic and improving flexibility in adjusting strategies.
Smart Images

Figure CN119484278A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of communication technology, and in particular to a method, device, electronic device and storage medium for adjusting a heartbeat interval. Background Art
[0002] With the development of mobile communication networks, real-time communication applications such as instant messaging and real-time video are becoming more and more common. These applications require the ability to maintain real-time communication between the client and the server. In order to ensure that the messages between the client and the server arrive in time, the client and the server usually communicate using a long connection of the Transmission Control Protocol (TCP).
[0003] When there is no data transmission between the client and the server for a long time or the network environment changes, the connection between the client and the server will be disconnected. In order to keep the communication link alive, the client usually sends a heartbeat data packet to the server after establishing a connection. The heartbeat data packet is a data packet between the client and the server to notify each other of their online status.
[0004] In the prior art, a heartbeat data packet is usually sent every fixed heartbeat interval. For example, a fixed heartbeat interval is set to 5 minutes, and the client sends a heartbeat data packet every 5 minutes.
[0005] However, in different network environments, the heartbeat intervals between the client and the server are often different. If the heartbeat interval is too short, a lot of invalid network traffic will be generated, resulting in a waste of bandwidth and an increase in the server load; and if the heartbeat interval is too long, the connection between the client and the server will be disconnected, causing the server to be unable to send messages to the client in time.
[0006] Therefore, how to set an accurate heartbeat interval is a technical problem that needs to be solved at present. Summary of the invention
[0007] Embodiments of the present application provide a method, device, electronic device, and storage medium for adjusting a heartbeat interval to improve the accuracy of setting the heartbeat interval.
[0008] The specific technical solutions provided by the embodiments of this application are as follows:
[0009] In a first aspect, an embodiment of the present application provides a method for adjusting a heartbeat interval, which is applied to a server, and the method includes:
[0010] Receive a heartbeat data packet sent by a client, the heartbeat data packet carrying the current status information of the client, the status information at least including: a heartbeat interval used when the client sends the heartbeat data packet, and a status parameter of the heartbeat interval;
[0011] Based on the state type represented by the state parameter, the state information is adjusted using an adjustment method corresponding to the state type to obtain state adjustment information, where the state adjustment information at least includes: a target heartbeat interval for the client to send a next heartbeat data packet, and a target state parameter for the target heartbeat interval;
[0012] A response packet carrying the state adjustment information is returned to the client, so that the client sends the next heartbeat data packet based on the target heartbeat interval indicated by the state adjustment information.
[0013] In a second aspect, an embodiment of the present application provides a method for adjusting a heartbeat interval, which is applied to a client, and the method includes:
[0014] Send a heartbeat data packet to the server, the heartbeat data packet carries the current status information of the client, the status information at least includes: the heartbeat interval used when sending the heartbeat data packet, and the status parameter of the heartbeat interval;
[0015] Receive a response packet returned by the server, the response packet carrying state adjustment information, the state adjustment information is: the server is based on the state type represented by the state parameter, using the adjustment method corresponding to the state type, the state adjustment information at least includes: the target heartbeat interval for sending the next heartbeat data packet, and the target state parameter of the target heartbeat interval;
[0016] The state adjustment information is used as new state information to be carried in the next heartbeat data packet sent and stored, and the next heartbeat data packet is sent to the server according to the target heartbeat interval indicated by the new state information.
[0017] In a third aspect, an embodiment of the present application provides a device for adjusting a heartbeat interval, which is applied to a server, and the device includes:
[0018] A first receiving module is used to receive a heartbeat data packet sent by a client, the heartbeat data packet carries the current status information of the client, and the status information at least includes: a heartbeat interval used when the client sends the heartbeat data packet, and a status parameter of the heartbeat interval;
[0019] A first processing module is used to adjust the state information based on the state type represented by the state parameter and adopt an adjustment method corresponding to the state type to obtain state adjustment information, wherein the state adjustment information at least includes: a target heartbeat interval for the client to send the next heartbeat data packet, and a target state parameter of the target heartbeat interval;
[0020] The return module is used to return a response packet carrying the state adjustment information to the client, so that the client sends the next heartbeat data packet based on the target heartbeat interval indicated by the state adjustment information.
[0021] In a possible implementation, the state parameter includes: the cumulative number of successful heartbeat data packets sent by the client according to the heartbeat interval, and the change stage of the heartbeat interval;
[0022] Based on the state type represented by the state parameter, the state information is adjusted using an adjustment method corresponding to the state type. When the state adjustment information is obtained, the first processing module is further used to:
[0023] Add 1 to the cumulative number of successes to obtain a new cumulative number of successes;
[0024] When the change phase is the detection phase, the state information is adjusted based on the new cumulative number of successes and the first detection number threshold to obtain state adjustment information;
[0025] When the change phase is a stable phase, the state information is adjusted based on the new accumulated number of successes and the first stable number threshold to obtain state adjustment information.
[0026] In a possible implementation, based on the new cumulative number of successes and the first detection number threshold, the state information is adjusted, and when the state adjustment information is obtained, the first processing module is further used to:
[0027] If the new cumulative number of successes is not greater than the first detection number threshold, the heartbeat interval is used as the target heartbeat interval, the new cumulative number of successes is used as the target cumulative number of successes of the target heartbeat interval, and the change stage is used as the target change stage of the target heartbeat interval;
[0028] If the new cumulative number of successes is greater than the first detection number threshold, the heartbeat interval is increased by the preset first time interval as the target heartbeat interval, and the target cumulative number of successes is set to 0, and the target change stage is determined based on the target heartbeat interval and the heartbeat interval threshold of the change stage.
[0029] In a possible implementation, when determining the target change stage based on the target heartbeat interval and the heartbeat interval threshold of the change stage, the first processing module is further used to:
[0030] If the target heartbeat interval is greater than the heartbeat interval threshold of the change stage, the target change stage is set to the stable stage;
[0031] If the target heartbeat interval is not greater than the heartbeat interval threshold of the change stage, the change stage is taken as the target change stage.
[0032] In a possible implementation, based on the new cumulative number of successes and the first stable number threshold, the state information is adjusted, and when the state adjustment information is obtained, the first processing module is further used to:
[0033] If the new cumulative number of successes is greater than the first stable number threshold, the heartbeat interval is used as the target heartbeat interval, the target cumulative number of successes for the target heartbeat interval is set to 0, and the target change stage of the target heartbeat interval is set to the detection stage;
[0034] If the new cumulative number of successes is not greater than the first stable number threshold, the heartbeat interval is used as the target heartbeat interval, the new cumulative number of successes is used as the target cumulative number of successes, and the change stage is used as the target change stage.
[0035] In a possible implementation, before receiving the heartbeat data packet sent by the client, the device further includes a first handshake module, where the first handshake module is used to:
[0036] Receive a first handshake data packet sent by the client, where the first handshake information carried by the first handshake data packet is empty;
[0037] Initialize the first handshake information to obtain initial state information, where the initial state information at least includes: an initial heartbeat interval for the client to send a first heartbeat data packet, and an initial state parameter of the initial heartbeat interval;
[0038] A first handshake reply packet carrying the initial state information is returned to the client, so that the client sends the first heartbeat data packet based on the initial heartbeat interval indicated by the initial state information.
[0039] In a possible implementation, before receiving the heartbeat data packet sent by the client, the device further includes a second handshake module, where the second handshake module is used to:
[0040] Receive a second handshake data packet sent by the client, where the second handshake information carried by the second handshake data packet is historical status information, and the historical status information at least includes: a historical heartbeat interval used when the client sent a previous heartbeat data packet, and a historical status parameter of the historical heartbeat interval;
[0041] Based on the historical state type represented by the historical state parameter, the second handshake information is updated to obtain state update information, where the state update information at least includes: an updated heartbeat interval for the client to send the next heartbeat data packet, and an updated state parameter for the updated heartbeat interval;
[0042] A second handshake reply packet carrying the status update information is returned to the client, so that the client sends the next heartbeat data packet based on the update heartbeat interval indicated by the status update information.
[0043] In a possible implementation, the historical state parameters include: the historical cumulative number of successful transmissions of the previous heartbeat data packet by the client according to the historical heartbeat interval, and the historical change stage of the historical heartbeat interval;
[0044] Based on the historical state type represented by the historical state parameter, the second handshake information is updated. When the state update information is obtained, the second handshake module is further used to:
[0045] If the historical change stage is the detection stage, and the historical cumulative number of successes is less than the second detection number threshold, the historical heartbeat interval is reduced by a preset second time interval as the update heartbeat interval, and the updated historical cumulative number of times of the update heartbeat interval is set to 0, and the update change stage of the update heartbeat interval is set to the stable stage;
[0046] If the historical change stage is a stable stage and the historical cumulative number of successes is less than the second stable number threshold, the historical heartbeat interval is reduced by a preset third time interval as the update heartbeat interval, and the historical cumulative number of updates of the update heartbeat interval is set to 0, and the update change stage in which the update heartbeat interval is located is set to a stable stage.
[0047] In a fourth aspect, an embodiment of the present application provides a device for adjusting a heartbeat interval, which is applied to a client, and the device includes:
[0048] The sending module is used to send a heartbeat data packet to the server, the heartbeat data packet carries the current status information of the client, and the status information at least includes: the heartbeat interval used when sending the heartbeat data packet, and the status parameter of the heartbeat interval;
[0049] A second receiving module is used to receive a response packet returned by the server, the response packet carrying state adjustment information, the state adjustment information is: the server is based on the state type represented by the state parameter, and the adjustment method corresponding to the state type is obtained, and the state adjustment information at least includes: a target heartbeat interval for sending the next heartbeat data packet, and a target state parameter of the target heartbeat interval;
[0050] The second processing module is used to use the state adjustment information as new state information carried in the next heartbeat data packet sent, store it, and send the next heartbeat data packet to the server according to the target heartbeat interval indicated by the new state information.
[0051] In a possible implementation, before sending the heartbeat data packet to the server, the device further includes a third handshake module, and the third handshake module is used to:
[0052] When establishing a connection with the server for the first time, a first handshake data packet is sent to the server, and the first handshake information carried in the first handshake data packet is empty;
[0053] Receive a first handshake reply packet returned by the server, the first handshake reply packet carrying initial state information, the initial state information is: obtained by the server initializing the first handshake information, the initial state information at least includes: an initial heartbeat interval for sending a first heartbeat data packet, and an initial state parameter of the initial heartbeat interval;
[0054] The initial state information is used as the first state information carried in the first heartbeat data packet sent and stored, and the first heartbeat data packet is sent to the server according to the initial heartbeat interval indicated by the first state information.
[0055] In a possible implementation, before sending the heartbeat data packet to the server, the device further includes a fourth handshake module, and the fourth handshake module is used to:
[0056] When it is not the first time to establish a connection with the server, a second handshake data packet is sent to the server, and the second handshake information carried by the second handshake data packet is historical state information, and the historical state information at least includes: a historical heartbeat interval used when sending a previous heartbeat data packet, and a historical state parameter of the historical heartbeat interval;
[0057] Receive a second handshake reply packet returned by the server, the second handshake reply packet carrying state update information, the state update information being obtained by updating the second handshake information based on the historical state type represented by the historical state parameter, the state update information at least including: an updated heartbeat interval for the client to send the next heartbeat data packet, and an updated state parameter for the updated heartbeat interval;
[0058] The state update information is used as the second state information carried in the next heartbeat data packet sent and stored, and the next heartbeat data packet is sent to the server according to the update heartbeat interval indicated by the second state information.
[0059] In a fifth aspect, an embodiment of the present application further provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the steps of any one of the above-mentioned heartbeat interval adjustment methods are implemented.
[0060] In a sixth aspect, an embodiment of the present application further provides a computer-readable storage medium having a computer program stored thereon, and when the computer program is executed by a processor, the steps of any one of the above-mentioned heartbeat interval adjustment methods are implemented.
[0061] In a seventh aspect, an embodiment of the present application further provides a computer program product, including computer instructions, which are executed by a processor to perform the steps of any of the above-mentioned heartbeat interval adjustment methods.
[0062] The beneficial effects of this application are as follows:
[0063] In an embodiment of the present application, the server receives a heartbeat data packet sent by the client, and then selects a corresponding adjustment method based on the state type represented by the state parameters contained in the state information carried by the heartbeat data packet, adjusts the state information, obtains the state adjustment information, and finally returns a response packet carrying the state adjustment information to the client, so that the client sends the next heartbeat data packet based on the target heartbeat interval indicated by the state adjustment information.
[0064] In this way, the heartbeat interval changes dynamically as the network environment changes, which is suitable for different network environments, can improve the accuracy of the heartbeat interval setting, and dynamically determine the optimal heartbeat interval in the current environment, reducing bandwidth and saving resources while maintaining connection stability. In addition, the adjustment strategy is controlled by the server, the client logic is lightweight, and it is easy to upgrade and modify the server's adjustment strategy, which is highly flexible. BRIEF DESCRIPTION OF THE DRAWINGS
[0065] Figure 1 A schematic diagram of abnormal disconnection;
[0066] Figure 2 A schematic diagram of an application scenario in an embodiment of the present application;
[0067] Figure 3 This is a first implementation flow chart of establishing a connection with the server in an embodiment of the present application;
[0068] Figure 4 A second implementation flow chart of establishing a connection with the server in an embodiment of the present application;
[0069] Figure 5 A schematic diagram of a process for obtaining status update information in an embodiment of the present application;
[0070] Figure 6 This is a first schematic diagram of obtaining status update information in an embodiment of the present application;
[0071] Figure 7 A second schematic diagram of obtaining status update information in an embodiment of the present application;
[0072] Figure 8 A first implementation flow chart of a method for adjusting a heartbeat interval provided in an embodiment of the present application;
[0073] Fig. 9 A schematic diagram of a process for obtaining state adjustment information in an embodiment of the present application;
[0074] Fig.10 A schematic diagram of a flow chart of adjusting state information during the detection phase in an embodiment of the present application;
[0075] Fig.11 This is a first schematic diagram of obtaining state adjustment information in an embodiment of the present application;
[0076] Fig.12 A schematic diagram of a process for determining a target change stage in an embodiment of the present application;
[0077] Fig.13 A schematic diagram of a process for adjusting the state information in the stable phase in an embodiment of the present application;
[0078] Fig.14 A second schematic diagram of obtaining state adjustment information in an embodiment of the present application;
[0079] Fig.15 This is a first implementation flow chart of establishing a connection by a client in an embodiment of the present application;
[0080] Fig.16 This is a schematic diagram of establishing a connection for the first time in an embodiment of the present application;
[0081] Fig.17 A second implementation flow chart of establishing a connection by a client in an embodiment of the present application;
[0082] Fig.18 This is a schematic diagram of establishing a connection not for the first time in an embodiment of the present application;
[0083] Fig.19 A second implementation flow chart of a method for adjusting a heartbeat interval provided in an embodiment of the present application;
[0084] Fig. 20 This is a schematic diagram of heartbeat interval adjustment in an embodiment of the present application;
[0085] Fig.21 A device for adjusting the heartbeat interval provided in an embodiment of the present application;
[0086] Fig. 22 Another device for adjusting the heartbeat interval provided in an embodiment of the present application;
[0087] Fig.23 A schematic diagram of a hardware structure of a computer device in an embodiment of the present application;
[0088] Fig.24 A schematic diagram of the hardware composition structure of another computer device in an embodiment of the present application. DETAILED DESCRIPTION
[0089] 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.
[0090] To facilitate understanding of the technical solutions provided in the embodiments of the present application, some key terms used in the embodiments of the present application are explained here:
[0091] TCP: It is a connection-oriented, reliable, byte stream-based transport layer communication protocol. It establishes a connection before sending data to ensure that the data is transmitted correctly and to ensure the reliability and integrity of the data.
[0092] Heartbeat data packet: a data packet sent by the client at the heartbeat interval to notify the server of its online status.
[0093] Heartbeat interval: The time interval at which the client sends heartbeat packets.
[0094] Detection phase: Continuously adjust the heartbeat interval to find the critical heartbeat interval that causes the connection between the client and the server to be disconnected in the current network environment.
[0095] Stable state: Fine-tune the critical heartbeat interval to find the optimal detection interval for the current network environment.
[0096] Heartbeat data packet response packet: It is a data packet returned to the client after the server responds to the heartbeat data packet, used to notify the client of its own online status.
[0097] Handshake packet: a packet sent by the client to the server to establish a connection with the server.
[0098] Handshake response packet: It is a data packet returned to the client after the server responds to the handshake data packet and is used to establish a connection with the client.
[0099] First detection times threshold: the upper limit of the cumulative number of successful heartbeat packets sent by the client according to one heartbeat interval during the detection phase.
[0100] Second detection times threshold: the lower limit of the cumulative number of successful heartbeat packets sent by the client according to one heartbeat interval during the detection phase.
[0101] First stable times threshold: the upper limit of the cumulative number of successful heartbeat packets sent by the client according to one heartbeat interval during the stable phase.
[0102] Second stable times threshold: the lower limit of the cumulative number of successful heartbeat packets sent by the client according to one heartbeat interval during the stable phase.
[0103] Heartbeat Interval Threshold: The maximum time interval allowed for the client to send heartbeat packets.
[0104] The following is a brief introduction to the design concept of the embodiment of the present application:
[0105] At present, with the development of mobile communication networks, real-time communication applications such as instant messaging and real-time video are becoming more and more common. These applications require the ability to maintain real-time communication between the client and the server. In order to ensure that the messages between the client and the server arrive in time, the client and the server usually use TCP long connections for communication.
[0106] When there is no data transmission between the client and the server for a long time or the network environment changes, the connection between the client and the server will be disconnected. Figure 1 As shown, it is a schematic diagram of an abnormal disconnection of a connection, wherein, after a long connection is established between a client and a server, the Network Address Translation (NAT) of the Internet Service Provider (ISP) will store a mapping relationship. When there is no data transmission between the client and the server for a long time, NAT will discard the mapping relationship, resulting in the non-existence of the mapping relationship and the abnormal disconnection of the connection.
[0107] In order to keep the communication link alive, the client usually sends a heartbeat data packet to the server after establishing a connection. The heartbeat data packet is a data packet between the client and the server to notify each other of their online status.
[0108] In the prior art, heartbeat packets are usually sent in the following two ways:
[0109] Method 1: A heartbeat data packet is sent every fixed heartbeat interval. For example, a fixed heartbeat interval is set to 5 minutes, and the client sends a heartbeat data packet every 5 minutes.
[0110] When adopting the first method, the heartbeat interval of the heartbeat data packet sent by the client to the server is often different in different network environments. If the heartbeat interval of sending the heartbeat data packet is too short, a lot of invalid network traffic will be generated, resulting in a waste of bandwidth and an increase in the server load; and if the heartbeat interval of sending the heartbeat data packet is too long, it is easy to cause the connection between the client and the server to be disconnected, causing the server to be unable to send messages to the client in time.
[0111] Method 2: The client adjusts the strategy according to the preset heartbeat interval, determines the heartbeat interval, and sends the heartbeat data packet according to the heartbeat interval.
[0112] When the second method is adopted, since the heartbeat interval adjustment strategy is solidified inside the client, the client logic is complicated, and it is inconvenient to adjust and upgrade the strategy, and the flexibility is low.
[0113] In view of this, in an embodiment of the present application, a method, device, electronic device and storage medium for adjusting a heartbeat interval are provided, wherein a server receives a heartbeat data packet sent by a client, the heartbeat data packet carries the current status information of the client, the status information at least includes: the heartbeat interval used when the client sends the heartbeat data packet, and the status parameter of the heartbeat interval, and then based on the status type represented by the status parameter, an adjustment method corresponding to the status type is used to adjust the status information to obtain status adjustment information, the status adjustment information at least includes: the target heartbeat interval for the client to send the next heartbeat data packet, and the target status parameter of the target heartbeat interval, and finally a response packet carrying the status adjustment information is returned to the client, so that the client sends the next heartbeat data packet based on the target heartbeat interval indicated by the status adjustment information.
[0114] In this way, the server adjusts the state information based on the state parameters and determines the target heartbeat interval for the client to send the next heartbeat data packet. This is applicable to different network environments, can improve the accuracy of the heartbeat interval setting, and reduces bandwidth and saves resources while maintaining connection stability. In addition, the adjustment strategy is controlled by the server, the client logic is lightweight, and it is easy to upgrade and modify the server's adjustment strategy, which is highly flexible.
[0115] After introducing the design concept of the embodiment of the present application, the application scenario set in the present application is briefly described below. It should be noted that the following scenario is only used to illustrate the embodiment of the present application and is not limited. In the specific implementation, the technical solution provided by the embodiment of the present application can be flexibly applied according to actual needs.
[0116] See also Figure 2 , Figure 2 The application scenario of the embodiment of the present application includes a terminal device 210, a server 220 and a client 230 installed on the terminal device. The terminal device 210 and the server 220 can communicate with each other through a communication network, and the client 230 and the server 220 can communicate with each other through a TCP long connection.
[0117] In an optional implementation, the communication network may be a wired network or a wireless network. Therefore, the terminal device 210 and the server 220 may be directly or indirectly connected via a wired or wireless communication. For example, the terminal device 210 may be indirectly connected to the server 220 via a wireless access point, or the terminal device 210 may be directly connected to the server 220 via the Internet, and this application does not limit this.
[0118] In the embodiment of the present application, the terminal device 210 includes but is not limited to mobile phones, tablet computers, laptop computers, desktop computers, e-book readers, intelligent voice interaction devices, smart home appliances, car terminals and other devices; various clients 230 are installed on the terminal device, which can be an application that supports functions such as video preview and video playback (such as a browser, game software, etc.), or it can be a web page, a small program, etc.
[0119] The server 220 is a background server corresponding to the client 230 installed in the terminal device 210. The server 220 can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (CDNs), and big data and artificial intelligence platforms.
[0120] It should be noted that Figure 2 The figure is only an example. In fact, the number of terminal devices 210 and server 220 is not limited and is not specifically limited in the embodiments of the present application.
[0121] The following describes the heartbeat interval adjustment method provided by the exemplary embodiment of the present application in combination with the application scenario described above and with reference to the accompanying drawings. It should be noted that the above application scenario is only shown to facilitate understanding of the spirit and principles of the present application, and the implementation of the present application is not limited in this respect.
[0122] Before receiving the heartbeat data packet sent by the client, the server needs to establish a connection with the client. Here, the server is used as an example for the execution subject. It can be divided into the following two situations.
[0123] The first case: establishing a connection with the client for the first time.
[0124] For details, see Figure 3 As shown in the figure, it is a first implementation flow chart of establishing a connection at the server end in the embodiment of the present application. Figure 3 , and explain in detail the specific operations performed:
[0125] Step 30: Receive the first handshake data packet sent by the client.
[0126] The first handshake information carried in the first handshake data packet is empty.
[0127] In an embodiment of the present application, when a connection is first established between a client and a server, the client sends a first handshake data packet, and the server receives the first handshake data packet sent by the client.
[0128] For example, the first handshake data packet sent by the client is handshake message 1, and the server receives the handshake message 1 sent by the client.
[0129] Step 31: Initialize the first handshake information to obtain initial status information.
[0130] Among them, the initial status information at least includes: the initial heartbeat interval at which the client sends the first heartbeat data packet, and the initial status parameters of the initial heartbeat interval. The initial status parameters include: the initial cumulative number of successful times the client sends heartbeat data packets according to the initial heartbeat interval, and the initial change stage of the initial heartbeat interval.
[0131] In the embodiment of the present application, after obtaining the first handshake information, the initial heartbeat interval is set to the preset minimum heartbeat interval, the initial cumulative number of successes is set to 0, and the initial change phase is set to the detection phase.
[0132] For example, if the minimum heartbeat interval is 1 minute, set the initial heartbeat interval to 1 minute.
[0133] Step 32: Return a first handshake response packet carrying the initial state information to the client, so that the client sends the first heartbeat data packet based on the initial heartbeat interval indicated by the initial state information.
[0134] In an embodiment of the present application, after obtaining the initial status information, a first handshake reply packet corresponding to the first handshake data packet is returned to the client, and the first handshake reply packet carries the initial status information, so that the client sends the first heartbeat data packet based on the initial heartbeat interval indicated by the initial status information.
[0135] In this way, when establishing a connection with a client for the first time, the server initializes the first handshake information, obtains the initial status information, and sends it to the client, and the client logic is lightweight.
[0136] The second case: This is not the first time a connection is established with the client.
[0137] For details, see Figure 4 As shown in the figure, it is a second implementation flow chart of establishing a connection at the server end in the embodiment of the present application. Figure 4 , and explain in detail the specific operations performed:
[0138] It is worth noting that the non-first time connection with the client can be disconnected and reconnected with the client in the detection phase, or disconnected and reconnected with the client in the stable phase.
[0139] Step 40: Receive a second handshake data packet sent by the client.
[0140] The second handshake information carried by the second handshake data packet is historical status information, and the historical status information at least includes: a historical heartbeat interval used when the client sends a previous heartbeat data packet, and a historical status parameter of the historical heartbeat interval.
[0141] In the embodiment of the present application, when it is not the first time to establish a connection between the client and the server, the client sends a second handshake data packet, and the server receives the second handshake data packet sent by the client.
[0142] For example, the second handshake data packet sent by the client is handshake message 2, and the server receives handshake message 2 sent by the client.
[0143] Step 41: Based on the historical state type represented by the historical state parameter, the second handshake information is updated to obtain state update information.
[0144] The status update information at least includes: an update heartbeat interval for the client to send the next heartbeat data packet, and an update status parameter of the update heartbeat interval.
[0145] Specifically, when executing step 41, the server performs the following operations. Figure 5 As shown, it is a schematic diagram of the process of obtaining status update information in the embodiment of the present application. Figure 5 , and explain in detail the specific operations performed:
[0146] The historical status parameters include: the historical cumulative number of successful transmissions of the previous heartbeat data packet by the client according to the historical heartbeat interval, and the historical change stage of the historical heartbeat interval.
[0147] Step 410: Determine whether the historical change stage is the detection stage, if so, execute step 411, otherwise, execute step 413.
[0148] Step 411: Determine whether the historical cumulative number of successes is less than the second detection number threshold, if so, execute step 412, otherwise, execute step 415.
[0149] Step 412: reduce the historical heartbeat interval by a preset second time interval as the update heartbeat interval, set the cumulative number of update history of the update heartbeat interval to 0, and set the update change stage of the update heartbeat interval to the stable stage.
[0150] In an embodiment of the present application, it is determined whether the historical change stage is the detection stage. If the historical change stage is the detection stage, it is determined whether the historical cumulative number of successes is less than the second detection number threshold. If the historical cumulative number of successes is less than the second detection number threshold, the historical heartbeat interval is reduced by a preset second time interval as the update heartbeat interval, and the updated historical cumulative number of updates of the update heartbeat interval is set to 0, and the update change stage in which the update heartbeat interval is located is set to a stable stage.
[0151] For example, see Figure 6 As shown, it is a first schematic diagram of obtaining status update information in an embodiment of the present application, assuming that the second detection number threshold is 3, the preset second time interval is 20 seconds, the historical change stage of the historical status information 1 is the detection stage, the historical cumulative number of successes is 1, and the historical heartbeat interval is 300 seconds. Then, the historical cumulative number of successes 1 is less than the second detection number threshold 3, the update heartbeat interval is 300-20=280 seconds, and the historical cumulative number of updates of the update heartbeat interval is set to 0, and the update change stage of the update heartbeat interval is set to the stable stage.
[0152] Step 413: Determine whether the historical cumulative number of successes is less than the second stable number threshold, if so, execute step 414, otherwise, execute step 415.
[0153] Step 414: reduce the historical heartbeat interval by a preset third time interval as the update heartbeat interval, set the cumulative number of update history of the update heartbeat interval to 0, and set the update change stage of the update heartbeat interval to the stable stage.
[0154] In an embodiment of the present application, it is determined whether the historical change stage is the detection stage. If the historical change stage is the stable stage, it is determined whether the historical cumulative number of successes is less than the second stable number threshold. If the historical cumulative number of successes is less than the second stable number threshold, the historical heartbeat interval is reduced by a preset third time interval as the update heartbeat interval, and the updated historical cumulative number of updates of the update heartbeat interval is set to 0, and the update change stage in which the update heartbeat interval is located is set to the stable stage.
[0155] For example, see Figure 7 As shown, it is a second schematic diagram of obtaining status update information in an embodiment of the present application, assuming that the second stable number threshold is 3, the preset third time interval is 20 seconds, the historical change stage of the historical status information 3 is the stable stage, the historical cumulative number of successes is 2, and the historical heartbeat interval is 360 seconds. Then, the historical cumulative number of successes 3 is less than the second stable number threshold 3, the update heartbeat interval is 360-20=340 seconds, and the historical cumulative number of updates of the update heartbeat interval is set to 0, and the update change stage of the update heartbeat interval is set to the stable stage.
[0156] Step 415: Use the historical heartbeat interval as the update heartbeat interval, use the historical cumulative number of successes as the update historical cumulative number of successes, and use the historical change stage as the update change stage.
[0157] In the embodiment of the present application, it is determined whether the historical change stage is the detection stage. If the historical change stage is the detection stage, it is determined whether the historical cumulative number of successes is less than the second detection number threshold. If the historical cumulative number of successes is not less than the second detection number threshold, the historical heartbeat interval is used as the update heartbeat interval, and the historical cumulative number of successes is used as the update history cumulative number, and the historical change stage is used as the update change stage. If the historical change stage is the stable stage, it is determined whether the historical cumulative number of successes is less than the second stable number threshold. If the historical cumulative number of successes is not less than the second stable number threshold, the historical heartbeat interval is used as the update heartbeat interval, and the historical cumulative number of successes is used as the update history cumulative number, and the historical change stage is used as the update change stage.
[0158] For example, Figure 6 As shown, assuming that the historical change stage of the historical status information 1 is the detection stage, the historical cumulative number of successes is 5, and the historical heartbeat interval is 300 seconds, the historical cumulative number of successes 5 is greater than the second detection number threshold 3, and the historical status information is used as the status update information, the updated heartbeat interval is 300 seconds, the updated historical cumulative number is 5, and the update change stage is the detection stage.
[0159] For example, Figure 7 As shown, assuming that the historical change stage of the historical status information 4 is the stable stage, the historical cumulative number of successes is 6, and the historical heartbeat interval is 360 seconds, the historical cumulative number of successes 6 is greater than the second stable number threshold 3, and the historical status information is used as the status update information, the updated heartbeat interval is 360 seconds, the updated historical cumulative number is 6, and the updated change stage is the stable stage.
[0160] In addition, it is worth noting that the second detection number threshold and the second stable number threshold can be 1 or greater than 1. The present embodiment of the application does not limit this. In order to set an accurate heartbeat interval, the second detection number threshold and the second stable number threshold can be set to be greater than 1. This can avoid the situation where the historical heartbeat interval is adjusted when the client accidentally succeeds in sending a heartbeat data packet according to the historical heartbeat interval, thereby improving the effectiveness of the heartbeat interval adjustment.
[0161] Step 42: Return a second handshake response packet carrying the status update information to the client, so that the client sends the next heartbeat data packet based on the update heartbeat interval indicated by the status update information.
[0162] In an embodiment of the present application, after obtaining the status update information, a second handshake reply packet corresponding to the second handshake data packet is returned to the client, and the second handshake reply packet carries the status update information, so that the client sends the next heartbeat data packet based on the update heartbeat interval indicated by the status update information.
[0163] See also Figure 8 As shown, it is a first implementation flow chart of a method for adjusting the heartbeat interval provided in an embodiment of the present application. Here, the server is used as an example for introduction. The specific implementation process of the method is as follows:
[0164] Step 80: Receive the heartbeat data packet sent by the client.
[0165] The heartbeat data packet carries the current status information of the client, and the status information at least includes: the heartbeat interval used by the client when sending the heartbeat data packet, and the status parameter of the heartbeat interval.
[0166] In an embodiment of the present application, after a connection is established with a client, a heartbeat data packet sent by the client is received.
[0167] Step 81: Based on the state type represented by the state parameter, the state information is adjusted using an adjustment method corresponding to the state type to obtain state adjustment information.
[0168] The state adjustment information at least includes: a target heartbeat interval for the client to send the next heartbeat data packet, and a target state parameter of the target heartbeat interval.
[0169] Specifically, when executing step 81, the server performs the following operations. Fig. 9 As shown, it is a schematic diagram of the process of obtaining state adjustment information in the embodiment of the present application. Fig. 9 , and explain in detail the specific operations performed:
[0170] The status parameters include: the cumulative number of successful heartbeat data packets sent by the client according to the heartbeat interval, and the change stage of the heartbeat interval.
[0171] Step 810: Add 1 to the cumulative number of successes to obtain a new cumulative number of successes.
[0172] In the embodiment of the present application, after the server receives the heartbeat data packet, it adds 1 to the cumulative number of successes to obtain a new cumulative number of successes.
[0173] For example, assuming that the cumulative number of successes is 3, the new cumulative number of successes is 3+1=4.
[0174] Step 811: Determine whether the change phase is the detection phase, if so, execute step 812, otherwise, execute step 813.
[0175] Step 812: Based on the new cumulative number of successes and the first detection number threshold, adjust the state information to obtain state adjustment information.
[0176] In an embodiment of the present application, it is determined whether the change stage is the detection stage. When the change stage is the detection stage, the heartbeat interval and state parameters are adjusted according to the new cumulative number of successes and the first detection number threshold to obtain the target heartbeat interval and the target state parameters of the target heartbeat interval.
[0177] Specifically, when executing step 812, the server performs the following operations. Fig.10 As shown, it is a schematic diagram of the flow chart of adjusting the state information in the detection phase in the embodiment of the present application. Fig.10 , and explain in detail the specific operations performed:
[0178] Step 8120: Determine whether the new cumulative number of successes is not greater than the first detection number threshold. If so, execute step 8121; otherwise, execute step 8122.
[0179] Among them, the first detection number threshold and the second detection number threshold can be the same, and the embodiment of the present application does not limit this.
[0180] Step 8121: The heartbeat interval is used as the target heartbeat interval, the new cumulative number of successes is used as the target cumulative number of successes of the target heartbeat interval, and the change stage is used as the target change stage of the target heartbeat interval.
[0181] In an embodiment of the present application, when the new cumulative number of successes is not greater than the first detection number threshold, the heartbeat interval is used as the target heartbeat interval, the new cumulative number of successes is used as the target cumulative number of successes for the target heartbeat interval, and the change stage is used as the target change stage of the target heartbeat interval.
[0182] For example, see Fig.11 As shown, this is the first schematic diagram for obtaining state adjustment information in an embodiment of the present application, assuming that the first detection number threshold is 3, the change stage of state information 1 is the detection stage, the new cumulative number of successes is 2, and the heartbeat interval is 5 minutes, then the new cumulative number of successes 2 is less than the first detection number threshold 3, the target heartbeat interval is 5 minutes, the target cumulative number of successes for the target heartbeat interval is 2, and the target change stage of the target heartbeat interval is the detection stage.
[0183] Step 8122: After increasing the heartbeat interval by a preset first time interval, the heartbeat interval is used as the target heartbeat interval, and the target cumulative number of successes is set to 0, and the target change stage is determined based on the target heartbeat interval and the heartbeat interval threshold of the change stage.
[0184] In an embodiment of the present application, when the new cumulative number of successes is greater than the first detection number threshold, the heartbeat interval is increased by a preset first time interval as the target heartbeat interval, and the target cumulative number of successes is set to 0, and the target change stage is determined based on the target heartbeat interval and the heartbeat interval threshold of the change stage.
[0185] For example, Fig.11 As shown, the preset first time interval is 1 minute, the change stage of the status information 2 is the detection stage, the new cumulative number of successes is 4, and the heartbeat interval is 5 minutes. The new cumulative number of successes 4 is greater than the first detection number threshold 3, the target heartbeat interval is 5+1=6 minutes, and the target cumulative number of successes of the target heartbeat interval is 0. Based on the target heartbeat interval and the heartbeat interval threshold of the change stage, the target change stage is determined.
[0186] In this way, the state information is adjusted according to the new accumulated number of successes and the first detection threshold, the heartbeat interval can be dynamically increased, and the critical heartbeat interval of the detection phase can be found.
[0187] Specifically, when determining the target change phase based on the target heartbeat interval and the heartbeat interval threshold of the change phase, the server specifically performs the following operations. Fig.12 As shown, it is a schematic diagram of the process of determining the target change stage in the embodiment of the present application. Fig.12 , and explain in detail the specific operations performed:
[0188] Step 8122-1: Determine whether the target heartbeat interval is greater than the heartbeat interval threshold of the change phase. If so, execute step 8122-2; otherwise, execute step 8122-3.
[0189] The heartbeat interval threshold in the changing phase is: the maximum heartbeat interval in the detecting phase.
[0190] Step 8122-2: Set the target change phase to the stable phase.
[0191] In the embodiment of the present application, when the target heartbeat interval is greater than the heartbeat interval threshold of the change stage, the target change stage is set to the stable stage.
[0192] For example, assuming that the heartbeat interval threshold value in the changing stage is 15 minutes and the target heartbeat interval is 16 minutes, the target heartbeat interval of 16 minutes is greater than the heartbeat interval threshold value of 15 minutes in the changing stage, and the target changing stage is set to the stable stage.
[0193] Step 8122-3: Set the change phase as the target change phase.
[0194] In the embodiment of the present application, when the target heartbeat interval is not greater than the heartbeat interval threshold of the change stage, the target change stage is set as the detection stage.
[0195] For example, assuming that the heartbeat interval threshold value in the change phase is 15 minutes and the target heartbeat interval is 5 minutes, the target heartbeat interval of 5 minutes is less than the heartbeat interval threshold value of 15 minutes in the change phase, and the target change phase is set to the detection phase.
[0196] In this way, when the heartbeat interval reaches the heartbeat interval threshold, the heartbeat interval change state detection phase is converted to the stable phase, and the heartbeat interval can be controlled within the heartbeat interval threshold, avoiding the heartbeat interval being too long, causing the server to be unable to send messages to the terminal device in time.
[0197] Step 813: Based on the new cumulative number of successes and the first stable number threshold, the state information is adjusted to obtain state adjustment information.
[0198] In an embodiment of the present application, it is determined whether the change stage is the detection stage. When the change stage is the stable stage, the heartbeat interval and state parameters are adjusted according to the new cumulative number of successes and the first stable number threshold to obtain the target heartbeat interval and the target state parameters of the target heartbeat interval.
[0199] Specifically, when executing step 813, the server performs the following operations. Fig.13 As shown, it is a schematic diagram of the process of adjusting the state information in the stable phase in the embodiment of the present application. Fig.13 , and explain in detail the specific operations performed:
[0200] Step 8130: Determine whether the new cumulative number of successes is greater than the first stable number threshold, if so, execute step 8131, otherwise, execute step 8132.
[0201] The first stable times threshold is much larger than the second stable times threshold.
[0202] Step 8131: The heartbeat interval is used as the target heartbeat interval, and the target cumulative number of successes of the target heartbeat interval is set to 0, and the target change stage of the target heartbeat interval is set to the detection stage.
[0203] In an embodiment of the present application, when the new cumulative number of successes is greater than the first stable number threshold, the heartbeat interval is used as the target heartbeat interval, the target cumulative number of successes of the target heartbeat interval is set to 0, and the target change stage of the target heartbeat interval is set to the detection stage.
[0204] For example, see Fig.14As shown, this is a second schematic diagram of obtaining state adjustment information in an embodiment of the present application, assuming that the first stable number threshold is 100, the change stage of state information 3 is the stable stage, the new cumulative number of successes is 101, and the heartbeat interval is 7 minutes. Then, the new cumulative number of successes 101 is greater than the first stable number threshold 100, the target heartbeat interval is 7 minutes, the target cumulative number of successes of the target heartbeat interval is 0, and the target change stage of the target heartbeat interval is the detection stage.
[0205] Step 8132: The heartbeat interval is used as the target heartbeat interval, the new cumulative number of successes is used as the target cumulative number of successes, and the change stage is used as the target change stage.
[0206] In an embodiment of the present application, when the new cumulative number of successes is not greater than the first detection number threshold, the heartbeat interval is used as the target heartbeat interval, the new cumulative number of successes is used as the target cumulative number of successes for the target heartbeat interval, and the change stage is used as the target change stage of the target heartbeat interval.
[0207] For example, Fig.14 As shown, assuming that the change stage of status information 4 is the stable stage, the new cumulative number of successes is 8, and the heartbeat interval is 6 minutes, the new cumulative number of successes 8 is less than the first detection number threshold 100, the target heartbeat interval is 6 minutes, the target cumulative number of successes of the target heartbeat interval is 8, and the target change stage of the target heartbeat interval is the stable stage.
[0208] In this way, the state information is adjusted according to the new cumulative number of successes and the first detection stability number threshold, that is, when the heartbeat interval is stable for a long time, the detection phase is entered to determine whether the heartbeat interval can be increased and determine a more accurate heartbeat interval.
[0209] Step 82: Return a response packet carrying the state adjustment information to the client, so that the client sends the next heartbeat data packet based on the target heartbeat interval indicated by the state adjustment information.
[0210] In an embodiment of the present application, after obtaining the state adjustment information, a response packet corresponding to the heartbeat data packet is returned to the client, and the response packet carries the state adjustment information, so that the client sends the next heartbeat data packet based on the target heartbeat interval indicated by the state adjustment information.
[0211] Furthermore, taking the client as the execution subject as an example, before the client sends a heartbeat data packet to the server, it is necessary to determine whether the connection status with the server is connected. If the connection status is not connected, it is necessary to establish a connection with the server.
[0212] When the following two situations occur, the client determines that the connection state with the server is disconnected.
[0213] Case 1: A heartbeat data packet is sent to the server. If no response packet is received from the server within the preset time range, the server responds with a timeout and determines that the connection status with the server is disconnected.
[0214] Case 2: If the connection identifier of the client's network library indicates that the client is not connected to the server, the connection status with the server is determined to be disconnected.
[0215] Among them, after determining that the connection state with the server is disconnected, establishing a connection with the server can be specifically divided into the following two situations.
[0216] The first case: establishing a connection with the server for the first time.
[0217] For details, see Fig.15 As shown in the figure, it is a first implementation flow chart of establishing a connection by the client in the embodiment of the present application. Fig.15 , and explain in detail the specific operations performed:
[0218] Step 150: When establishing a connection with the server for the first time, send a first handshake data packet to the server.
[0219] The first handshake information carried in the first handshake data packet is empty.
[0220] In an embodiment of the present application, when a connection is first established between a client and a server, the client sends a first handshake data packet to the server.
[0221] For example, see Fig.16 As shown, it is a schematic diagram of establishing a connection for the first time in an embodiment of the present application. The client sends a first handshake data packet to the server: handshake message 1, and the first handshake information carried by handshake message 1 is empty.
[0222] Step 151: Receive the first handshake response packet returned by the server.
[0223] The first handshake reply packet carries initial state information, which is obtained by the server initializing the first handshake information. The initial state information at least includes an initial heartbeat interval for sending the first heartbeat data packet and an initial state parameter of the initial heartbeat interval.
[0224] In the embodiment of the present application, after receiving the first handshake data packet, the server initializes the first handshake information carried in the first handshake data packet to obtain the initial state information, and the client receives the first handshake reply packet carrying the initial state information returned by the server.
[0225] For example, Fig.16As shown, the first handshake response packet received by the client from the server is: handshake response packet 1, and the initial status information includes: the initial heartbeat interval is 1 minute, the initial cumulative number of successes is 0, and the initial change stage is the detection stage.
[0226] Step 152: Use the initial state information as the first state information carried by the first heartbeat data packet, store it, and send the first heartbeat data packet to the server according to the initial heartbeat interval indicated by the first state information.
[0227] In an embodiment of the present application, the client uses the initial status information as the first status information carried by the first heartbeat data packet sent, and stores it in a status database, then selects the first status information from the status database, and sends the first heartbeat data packet to the server according to the initial heartbeat interval indicated by the first status information.
[0228] For example, Fig.16 As shown, the initial state information is used as the first state information carried by the first heartbeat data packet sent, and is stored in the state database. After waiting for the initial heartbeat interval of 1 minute, the first heartbeat data packet carrying the first state information is sent to the server.
[0229] In this way, when establishing a connection with the client for the first time, the client only needs to send the first handshake data packet, receive the first handshake reply packet carrying the initial state information returned by the server, and store the initial state information. The client does not need to calculate the initial state information, and the logic is lightweight.
[0230] Among them, each state information in the state database includes at least a heartbeat interval field, a change phase field and a cumulative success number field. The heartbeat interval field is not transparent to the client, that is, the client needs to understand the meaning of the heartbeat interval word and send heartbeat data packets according to the heartbeat interval. The change phase field and the cumulative success number field are transparent to the client, that is, the client does not need to understand the meaning of the change phase field and the cumulative success number field. The detailed fields of a state information are shown in Table 1:
[0231] Table 1
[0232]
[0233] The second case: This is not the first time to establish a connection with the server.
[0234] For details, see Fig.17 As shown in the figure, it is a second implementation flow chart of establishing a connection by the client in the embodiment of the present application. Fig.17 , and explain in detail the specific operations performed:
[0235] It is worth noting that the non-first time connection with the server can be disconnected and reconnected with the server during the detection phase, or disconnected and reconnected with the server during the stable phase.
[0236] Step 170: When it is not the first time to establish a connection with the server, send a second handshake data packet to the server.
[0237] The second handshake information carried by the second handshake data packet is historical status information, and the historical status information at least includes: a historical heartbeat interval used when sending a previous heartbeat data packet, and a historical status parameter of the historical heartbeat interval.
[0238] In an embodiment of the present application, when a connection is not established for the first time between a client and a server, the client reads the most recent historical status information from a status database as second handshake information, and sends a second handshake data packet carrying the second handshake information to the server.
[0239] For example, see Fig.18 As shown, it is a schematic diagram of establishing a connection not for the first time in an embodiment of the present application. The client reads the most recent historical status information from the status database. The historical status information includes: the historical heartbeat interval is 300 seconds, the historical cumulative number of successes is 1, and the historical change stage is the detection stage. The historical status information is used as the second handshake information, and a handshake message 2 carrying the second handshake information is sent to the server.
[0240] Step 171: Receive the second handshake response packet returned by the server.
[0241] Among them, the second handshake reply packet carries status update information, and the status update information is: the server updates the second handshake information based on the historical status type represented by the historical status parameters, and the status update information at least includes: the updated heartbeat interval for the client to send the next heartbeat data packet, and the updated status parameters of the updated heartbeat interval.
[0242] In the embodiment of the present application, after receiving the second handshake data packet, the server updates the second handshake information carried in the second handshake data packet to obtain status update information, and the client receives the second handshake reply packet carrying the status update information returned by the server.
[0243] For example, Fig.18 As shown, the second handshake response packet received by the client from the server is: handshake response packet 2, and the status update information includes: the update heartbeat interval is 280 seconds, the cumulative number of update successes is 0, and the update change stage is the stable stage.
[0244] Step 172: Use the status update information as the second status information carried in the next heartbeat data packet sent, store it, and send the next heartbeat data packet to the server according to the update heartbeat interval indicated by the second status information.
[0245] In an embodiment of the present application, the client uses the status update information as the second status information carried by the next heartbeat data packet and stores it in the status database, then selects the second status information from the status database, and sends the next heartbeat data packet to the server according to the updated heartbeat interval indicated by the second status information.
[0246] For example, Fig.18 As shown, the state update information is used as the second state information carried by the next heartbeat data packet, stored in the state database, and after waiting for the heartbeat interval to be updated for 280 seconds, a heartbeat data packet 4 carrying the second state information is sent to the server.
[0247] In this way, since the client's local status database stores historical status information, there is no need to initialize the status information after the connection is disconnected and reconnected. The most recent historical status information can be directly read and sent to the server, so that the server can update the historical status information and obtain the status update information. According to the update heartbeat interval indicated by the status update information, the next heartbeat data packet is sent to the server, avoiding repeated initialization operations and improving the efficiency of heartbeat interval adjustment.
[0248] See also Fig.19 As shown, it is a second implementation flow chart of a method for adjusting the heartbeat interval provided in an embodiment of the present application. Here, the client is used as an example for introduction. The specific implementation process of the method is as follows:
[0249] Step 190: Send a heartbeat data packet to the server.
[0250] The heartbeat data packet carries the current status information of the client, and the status information at least includes: the heartbeat interval used when sending the heartbeat data packet, and the status parameter of the heartbeat interval.
[0251] In an embodiment of the present application, after a connection is established with the server, a heartbeat data packet is sent to the server.
[0252] For example, see Fig. 20 As shown, it is a schematic diagram of the heartbeat interval adjustment in the embodiment of the present application. The client reads the status information 5 corresponding to the heartbeat data packet 5 from the status database. The status information 5 includes: the heartbeat interval is 5 minutes, the cumulative number of successful updates is 2, the update change stage is the detection stage, and the heartbeat data packet 5 carrying the status information 5 is sent to the server.
[0253] Step 191: Receive the response packet returned by the server.
[0254] Among them, the response packet carries state adjustment information, which is: the server obtains the state type based on the state parameter representation by the adjustment method corresponding to the state type, and the state adjustment information at least includes: the target heartbeat interval for sending the next heartbeat data packet, and the target state parameter of the target heartbeat interval.
[0255] In an embodiment of the present application, after the server receives the heartbeat data packet, it adjusts the state information carried in the heartbeat data packet based on the state type represented by the state parameter and adopts the adjustment method corresponding to the state type to obtain the state adjustment information, and the client receives the response packet returned by the server carrying the state adjustment information.
[0256] For example, Fig. 20 As shown, the response packet received by the client from the server is: response packet 5, and the state adjustment information includes: the target heartbeat interval is 6 minutes, the target cumulative success number is 0, and the target change stage is the detection stage.
[0257] Step 192: Use the state adjustment information as new state information to be carried in the next heartbeat data packet, store it, and send the next heartbeat data packet to the server according to the target heartbeat interval indicated by the new state information.
[0258] In an embodiment of the present application, the client uses the state adjustment information as the new state information carried by the next heartbeat data packet and stores it in the state database, then selects the new state information from the state database, and sends the next heartbeat data packet to the server according to the target heartbeat interval indicated by the new state information.
[0259] For example, Fig. 20 As shown, the state adjustment information is used as the new state information carried by the next heartbeat data packet, stored in the state database, and after waiting for the target heartbeat interval of 6 minutes, a heartbeat data packet 6 carrying the new state information is sent to the server.
[0260] In this way, the server adjusts the status information, and the client only needs to send the next heartbeat data packet to the server according to the target heartbeat interval indicated by the new status information after receiving the response packet. There is no need to calculate the target heartbeat interval, and the logic is lightweight.
[0261] Based on the same technical concept, see Fig.21 As shown, the embodiment of the present application further provides a heartbeat interval adjustment device 2100, which is applied to the server, and the device includes:
[0262] The first receiving module 2101 is used to receive a heartbeat data packet sent by a client, where the heartbeat data packet carries the current status information of the client, and the status information at least includes: a heartbeat interval used when the client sends the heartbeat data packet, and a status parameter of the heartbeat interval;
[0263] The first processing module 2102 is used to adjust the state information based on the state type represented by the state parameter and adopt an adjustment method corresponding to the state type to obtain state adjustment information, where the state adjustment information at least includes: a target heartbeat interval for the client to send the next heartbeat data packet, and a target state parameter of the target heartbeat interval;
[0264] The return module 2103 is used to return a response packet carrying the state adjustment information to the client, so that the client sends the next heartbeat data packet based on the target heartbeat interval indicated by the state adjustment information.
[0265] In a possible implementation, the state parameter includes: the cumulative number of successful heartbeat data packets sent by the client according to the heartbeat interval, and the change stage of the heartbeat interval;
[0266] Based on the state type represented by the state parameter, the state information is adjusted using an adjustment method corresponding to the state type. When the state adjustment information is obtained, the first processing module 2102 is further used to:
[0267] Add 1 to the cumulative number of successes to obtain a new cumulative number of successes;
[0268] When the change phase is the detection phase, the state information is adjusted based on the new cumulative number of successes and the first detection number threshold to obtain state adjustment information;
[0269] When the change phase is a stable phase, the state information is adjusted based on the new accumulated number of successes and the first stable number threshold to obtain state adjustment information.
[0270] In a possible implementation, based on the new cumulative number of successes and the first detection number threshold, the state information is adjusted. When the state adjustment information is obtained, the first processing module 2102 is further used to:
[0271] If the new cumulative number of successes is not greater than the first detection number threshold, the heartbeat interval is used as the target heartbeat interval, the new cumulative number of successes is used as the target cumulative number of successes of the target heartbeat interval, and the change stage is used as the target change stage of the target heartbeat interval;
[0272] If the new cumulative number of successes is greater than the first detection number threshold, the heartbeat interval is increased by the preset first time interval as the target heartbeat interval, and the target cumulative number of successes is set to 0, and the target change stage is determined based on the target heartbeat interval and the heartbeat interval threshold of the change stage.
[0273] In a possible implementation, when determining the target change stage based on the target heartbeat interval and the heartbeat interval threshold of the change stage, the first processing module 2102 is further configured to:
[0274] If the target heartbeat interval is greater than the heartbeat interval threshold of the change stage, the target change stage is set to the stable stage;
[0275] If the target heartbeat interval is not greater than the heartbeat interval threshold of the change stage, the change stage is taken as the target change stage.
[0276] In a possible implementation, based on the new cumulative number of successes and the first stable number threshold, the state information is adjusted. When the state adjustment information is obtained, the first processing module 2102 is further used to:
[0277] If the new cumulative number of successes is greater than the first stable number threshold, the heartbeat interval is used as the target heartbeat interval, the target cumulative number of successes for the target heartbeat interval is set to 0, and the target change stage of the target heartbeat interval is set to the detection stage;
[0278] If the new cumulative number of successes is not greater than the first stable number threshold, the heartbeat interval is used as the target heartbeat interval, the new cumulative number of successes is used as the target cumulative number of successes, and the change stage is used as the target change stage.
[0279] In a possible implementation, before receiving the heartbeat data packet sent by the client, the device further includes a first handshake module 2104, and the first handshake module 2104 is used to:
[0280] Receive a first handshake data packet sent by the client, where the first handshake information carried by the first handshake data packet is empty;
[0281] Initialize the first handshake information to obtain initial state information, where the initial state information at least includes: an initial heartbeat interval for the client to send a first heartbeat data packet, and an initial state parameter of the initial heartbeat interval;
[0282] A first handshake reply packet carrying the initial state information is returned to the client, so that the client sends the first heartbeat data packet based on the initial heartbeat interval indicated by the initial state information.
[0283] In a possible implementation, before receiving the heartbeat data packet sent by the client, the device further includes a second handshake module 2105, and the second handshake module 2105 is used to:
[0284] Receive a second handshake data packet sent by the client, where the second handshake information carried by the second handshake data packet is historical status information, and the historical status information at least includes: a historical heartbeat interval used when the client sent a previous heartbeat data packet, and a historical status parameter of the historical heartbeat interval;
[0285] Based on the historical state type represented by the historical state parameter, the second handshake information is updated to obtain state update information, where the state update information at least includes: an updated heartbeat interval for the client to send the next heartbeat data packet, and an updated state parameter for the updated heartbeat interval;
[0286] A second handshake reply packet carrying the status update information is returned to the client, so that the client sends the next heartbeat data packet based on the update heartbeat interval indicated by the status update information.
[0287] In a possible implementation, the historical state parameters include: the historical cumulative number of successful transmissions of the previous heartbeat data packet by the client according to the historical heartbeat interval, and the historical change stage of the historical heartbeat interval;
[0288] Based on the historical state type represented by the historical state parameter, the second handshake information is updated. When the state update information is obtained, the second handshake module 2105 is further used to:
[0289] If the historical change stage is the detection stage, and the historical cumulative number of successes is less than the second detection number threshold, the historical heartbeat interval is reduced by a preset second time interval as the update heartbeat interval, and the updated historical cumulative number of times of the update heartbeat interval is set to 0, and the update change stage of the update heartbeat interval is set to the stable stage;
[0290] If the historical change stage is a stable stage and the historical cumulative number of successes is less than the second stable number threshold, the historical heartbeat interval is reduced by a preset third time interval as the update heartbeat interval, and the historical cumulative number of updates of the update heartbeat interval is set to 0, and the update change stage in which the update heartbeat interval is located is set to a stable stage.
[0291] Based on the same technical concept, see Fig. 22 As shown, the embodiment of the present application also provides another heartbeat interval adjustment device 2200, which is applied to a client, and the device includes:
[0292] The sending module 2201 is used to send a heartbeat data packet to the server, where the heartbeat data packet carries the current status information of the client, and the status information at least includes: the heartbeat interval used when sending the heartbeat data packet, and the status parameter of the heartbeat interval;
[0293] The second receiving module 2202 is used to receive a response packet returned by the server, the response packet carrying state adjustment information, the state adjustment information is: the server is based on the state type represented by the state parameter, and the adjustment method corresponding to the state type is obtained, and the state adjustment information at least includes: a target heartbeat interval for sending the next heartbeat data packet, and a target state parameter of the target heartbeat interval;
[0294] The second processing module 2203 is used to use the state adjustment information as new state information to be carried in the next heartbeat data packet, store it, and send the next heartbeat data packet to the server according to the target heartbeat interval indicated by the new state information.
[0295] In a possible implementation, before sending the heartbeat data packet to the server, the device further includes a third handshake module 2204, and the third handshake module 2204 is used to:
[0296] When establishing a connection with the server for the first time, a first handshake data packet is sent to the server, and the first handshake information carried in the first handshake data packet is empty;
[0297] Receive a first handshake reply packet returned by the server, the first handshake reply packet carrying initial state information, the initial state information is: obtained by the server initializing the first handshake information, the initial state information at least includes: an initial heartbeat interval for sending a first heartbeat data packet, and an initial state parameter of the initial heartbeat interval;
[0298] The initial state information is used as the first state information carried in the first heartbeat data packet sent and stored, and the first heartbeat data packet is sent to the server according to the initial heartbeat interval indicated by the first state information.
[0299] In a possible implementation, before sending the heartbeat data packet to the server, the device further includes a fourth handshake module 2205, and the fourth handshake module 2205 is used to:
[0300] When it is not the first time to establish a connection with the server, a second handshake data packet is sent to the server, and the second handshake information carried by the second handshake data packet is historical state information, and the historical state information at least includes: a historical heartbeat interval used when sending a previous heartbeat data packet, and a historical state parameter of the historical heartbeat interval;
[0301] Receive a second handshake reply packet returned by the server, the second handshake reply packet carrying state update information, the state update information being obtained by updating the second handshake information based on the historical state type represented by the historical state parameter, the state update information at least including: an updated heartbeat interval for the client to send the next heartbeat data packet, and an updated state parameter for the updated heartbeat interval;
[0302] The state update information is used as the second state information carried in the next heartbeat data packet sent and stored, and the next heartbeat data packet is sent to the server according to the update heartbeat interval indicated by the second state information.
[0303] Based on the same inventive concept as the above method embodiment, the present application embodiment also provides a computing device. In one embodiment, the computing device may be a server, such as Figure 2 In this embodiment, the structure of the computer device 2300 is as follows: Fig.23 As shown, it may include at least a memory 2301 , a communication module 2303 , and at least one processor 2302 .
[0304] The memory 2301 is used to store computer programs executed by the processor 2302. The memory 2301 may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system and programs required for running the instant messaging function, etc.; the data storage area may store various instant messaging information and operation instruction sets, etc.
[0305] The memory 2301 may be a volatile memory, such as a random-access memory (RAM); the memory 2301 may also be a non-volatile memory, such as a read-only memory, a flash memory, a hard disk drive (HDD) or a solid-state drive (SSD); or the memory 2301 may be any other medium that can be used to carry or store a desired computer program in the form of instructions or data structures and can be accessed by a computer, but is not limited thereto. The memory 2301 may be a combination of the above memories.
[0306] The processor 2302 may include one or more central processing units (CPU) or a digital processing unit, etc. The processor 2302 is configured to implement the above-mentioned heartbeat interval adjustment method when calling the computer program stored in the memory 2301 .
[0307] The communication module 2303 is used to communicate with terminal devices and other servers.
[0308] The specific connection medium between the memory 2301, the communication module 2303 and the processor 2302 is not limited in the embodiment of the present application. Fig.23 In the embodiment, the memory 2301 and the processor 2302 are connected via a bus 2304. The bus 2304 is connected to the processor 2302 via a bus 2304. Fig.23 The connections between the other components are described with bold lines, which are only for illustrative purposes and are not intended to be limiting. The bus 2304 can be divided into an address bus, a data bus, a control bus, etc. For ease of description, Fig.23 The diagram shows that only one thick line is used, but this does not mean that there is only one bus or only one type of bus.
[0309] The memory 2301 stores a computer storage medium, and the computer storage medium stores computer executable instructions, and the computer executable instructions are used to implement the heartbeat interval adjustment method of the embodiment of the present application. The processor 2302 is used to execute the above-mentioned heartbeat interval adjustment method.
[0310] In another embodiment, the computing device may also be other computing devices, such as Figure 1 In this embodiment, the structure of the computing device can be as follows: Fig.24 As shown, it includes: a communication component 2410, a memory 2420, a display unit 2430, a camera 2440, a sensor 2450, an audio circuit 2460, a Bluetooth module 2470, a processor 2480 and other components.
[0311] The communication component 2410 is used to communicate with the server. In some embodiments, a wireless fidelity (WiFi) module may be included. The WiFi module belongs to a short-range wireless transmission technology. The electronic device can help the object to send and receive information through the WiFi module.
[0312] The memory 2420 can be used to store software programs and data. The processor 2480 executes various functions and data processing of the terminal device 240 by running the software programs or data stored in the memory 2420. The memory 2420 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other volatile solid-state storage devices. The memory 2420 stores an operating system that enables the terminal device 210 to run. In the present application, the memory 2420 can store an operating system and various application programs, and can also store a computer program for executing the method for adjusting the heartbeat interval of the embodiment of the present application.
[0313] The display unit 2430 can also be used to display information input by the object or information provided to the object and a graphical user interface (GUI) of various menus of the terminal device 210. Specifically, the display unit 2430 may include a display screen 2432 disposed on the front of the terminal device 210. The display screen 2432 may be configured in the form of a liquid crystal display, a light emitting diode, etc. The display unit 2430 can be used to display the continuous task completion interface, the output interface of each completion number, etc. in the embodiment of the present application.
[0314] The display unit 2430 can also be used to receive input digital or character information, and generate signal input related to the object setting and function control of the terminal device 210. Specifically, the display unit 2430 may include a touch screen 2431 set on the front of the terminal device 210, which can collect touch operations of objects on or near it, such as clicking a button, dragging a scroll box, etc.
[0315] The touch screen 2431 can be covered on the display screen 2432, or the touch screen 2431 and the display screen 2432 can be integrated to realize the input and output functions of the physical terminal device 210, and the integrated display screen can be referred to as a touch display screen. In this application, the display unit 2430 can display the application and the corresponding operation steps.
[0316] The camera 2440 can be used to capture static images, and the subject can publish the images taken by the camera 2440 through the application. The camera 2440 can be one or more. The object generates an optical image through the lens and projects it onto the photosensitive element. The photosensitive element can be a charge coupled device (CCD) or a complementary metal-oxide-semiconductor (CMOS) phototransistor. The photosensitive element converts the optical signal into an electrical signal, and then passes the electrical signal to the processor 2480 to convert it into a digital image signal.
[0317] The physical terminal device may also include at least one sensor 2450, such as an acceleration sensor 2451, a distance sensor 2452, a fingerprint sensor 2453, and a temperature sensor 2454. The terminal device may also be configured with other sensors such as a gyroscope, a barometer, a hygrometer, a thermometer, an infrared sensor, a light sensor, and a motion sensor.
[0318] The audio circuit 2460, the speaker 2461, and the microphone 2462 can provide an audio interface between the object and the terminal device 210. The audio circuit 2460 can transmit the electrical signal converted from the received audio data to the speaker 2461, which is converted into a sound signal for output. The physical terminal device 210 can also be configured with a volume button for adjusting the volume of the sound signal. On the other hand, the microphone 2462 converts the collected sound signal into an electrical signal, which is received by the audio circuit 2460 and converted into audio data, and then the audio data is output to the communication component 2410 to be sent to, for example, another physical terminal device 240, or the audio data is output to the memory 2420 for further processing.
[0319] The Bluetooth module 2470 is used to exchange information with other Bluetooth devices having Bluetooth modules through the Bluetooth protocol. For example, the physical terminal device can establish a Bluetooth connection with a wearable electronic device (such as a smart watch) that also has a Bluetooth module through the Bluetooth module 2470 to exchange data.
[0320] The processor 2480 is the control center of the physical terminal device. It uses various interfaces and lines to connect various parts of the entire terminal. It executes various functions of the terminal device and processes data by running or executing software programs stored in the memory 2420 and calling data stored in the memory 2420. In some embodiments, the processor 2480 may include one or more processing units; the processor 2480 may also integrate an application processor and a baseband processor, wherein the application processor mainly processes the operating system, user interface, and application programs, and the baseband processor mainly processes wireless communications. It is understandable that the above-mentioned baseband processor may not be integrated into the processor 2480. In the present application, the processor 2480 can run the heartbeat interval adjustment method of the embodiment of the present application. In addition, the processor 2480 is coupled to the display unit 2430.
[0321] In some possible implementations, various aspects of the method for adjusting the heartbeat interval provided in the present application may also be implemented in the form of a program product, which includes a computer program. When the program product is run on a computing device, the computer program is used to enable the computing device to execute the steps of the method for adjusting the heartbeat interval according to various exemplary embodiments of the present application described above in this specification.
[0322] The program product may use any combination of one or more readable media. The readable medium may be a readable signal medium or a readable storage medium. The readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of readable storage media (a non-exhaustive list) include: an electrical connection with one or more wires, a portable disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above.
[0323] The program product of the embodiment of the present application may adopt a portable compact disk read-only memory (CD-ROM) and include a computer program, and can be run on an electronic device. However, the program product of the present application is not limited thereto, and in this document, a readable storage medium may be any tangible medium containing or storing a program, which can be used by or in combination with a command execution system, apparatus, or device.
[0324] A readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, wherein a readable computer program is carried. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the foregoing. A readable signal medium may also be any readable medium other than a readable storage medium, which may send, propagate, or transmit a program for use by or in conjunction with a command execution system, apparatus, or device.
[0325] The computer program embodied on the readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.
[0326] The computer program for performing the operations of the present application may be written in any combination of one or more programming languages, including object-oriented programming languages such as Java, C++, etc., and conventional procedural programming languages such as "C" or similar programming languages. The computer program may be executed entirely on the user's computer device, partially on the user's computer device, as a separate software package, partially on the user's computer device and partially on a remote computer device, or entirely on the remote computer device. In the case of a remote computer device, the remote computer device may be connected to the user's computer device through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer device (e.g., via the Internet using an Internet service provider).
[0327] It should be noted that, although several units or subunits of the device are mentioned in the above detailed description, this division is merely exemplary and not mandatory. In fact, according to the embodiments of the present application, the features and functions of two or more units described above can be embodied in one unit. Conversely, the features and functions of one unit described above can be further divided into multiple units to be embodied.
[0328] In addition, although the operations of the method of the present application are described in a specific order in the drawings, this does not require or imply that the operations must be performed in this specific order, or that all the operations shown must be performed to achieve the desired results. Additionally or alternatively, some steps may be omitted, multiple steps may be combined into one step, and / or one step may be decomposed into multiple steps.
[0329] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that include computer-usable program code.
[0330] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0331] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0332] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0333] Obviously, those skilled in the art can make various changes and modifications to the present application without departing from the spirit and scope of the present application. Thus, if these modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is also intended to include these modifications and variations.
Claims
1. A method for adjusting a heartbeat interval, characterized in that: Applied to the server, including: Receive a heartbeat data packet sent by a client, the heartbeat data packet carrying current status information of the client, the status information at least including: a heartbeat interval used by the client when sending the heartbeat data packet, and a status parameter of the heartbeat interval; Based on the state type represented by the state parameter, the state information is adjusted using an adjustment method corresponding to the state type to obtain state adjustment information, wherein the state adjustment information at least includes: a target heartbeat interval for the client to send a next heartbeat data packet, and a target state parameter of the target heartbeat interval; A response packet carrying the state adjustment information is returned to the client, so that the client sends the next heartbeat data packet based on the target heartbeat interval indicated by the state adjustment information.
2. The method according to claim 1, characterized in that The state parameters include: the cumulative number of successful times of the client sending the heartbeat data packet according to the heartbeat interval, and the change stage of the heartbeat interval; The state type represented by the state parameter, adjusting the state information by using an adjustment method corresponding to the state type, and obtaining the state adjustment information, includes: Add 1 to the cumulative number of successes to obtain a new cumulative number of successes; When the change phase is the detection phase, adjusting the state information based on the new accumulated number of successes and the first detection number threshold to obtain state adjustment information; When the change phase is a stable phase, the state information is adjusted based on the new accumulated number of successes and a first stable number threshold to obtain state adjustment information.
3. The method according to claim 2, characterized in that The adjusting the state information based on the new cumulative number of successes and the first detection number threshold to obtain state adjustment information includes: If the new cumulative number of successes is not greater than the first detection number threshold, the heartbeat interval is used as the target heartbeat interval, the new cumulative number of successes is used as the target cumulative number of successes for the target heartbeat interval, and the change stage is used as the target change stage for the target heartbeat interval; If the new cumulative number of successes is greater than the first detection number threshold, the heartbeat interval is increased by the preset first time interval as the target heartbeat interval, and the target cumulative number of successes is set to 0, and the target change stage is determined based on the target heartbeat interval and the heartbeat interval threshold of the change stage.
4. The method according to claim 3, characterized in that The step of determining the target change stage based on the target heartbeat interval and the heartbeat interval threshold of the change stage comprises: If the target heartbeat interval is greater than the heartbeat interval threshold of the change stage, setting the target change stage to a stable stage; If the target heartbeat interval is not greater than the heartbeat interval threshold of the change stage, the change stage is used as the target change stage.
5. The method according to claim 2, characterized in that The adjusting the state information based on the new cumulative number of successes and the first stable number threshold to obtain state adjustment information includes: If the new cumulative number of successes is greater than the first stable number threshold, the heartbeat interval is used as the target heartbeat interval, the target cumulative number of successes of the target heartbeat interval is set to 0, and the target change stage of the target heartbeat interval is set to the detection stage; If the new cumulative number of successes is not greater than the first stable number threshold, the heartbeat interval is used as the target heartbeat interval, the new cumulative number of successes is used as the target cumulative number of successes, and the change stage is used as the target change stage.
6. The method according to any one of claims 1 to 5, characterized in that: Before receiving the heartbeat data packet sent by the client, the method further includes: Receive a first handshake data packet sent by the client, where the first handshake information carried by the first handshake data packet is empty; Initialize the first handshake information to obtain state initial information, the state initial information at least including: an initial heartbeat interval for the client to send a first heartbeat data packet, and an initial state parameter of the initial heartbeat interval, wherein the change stage of the initial heartbeat interval contained in the initial state parameter is the detection stage; A first handshake reply packet carrying the initial state information is returned to the client, so that the client sends a first heartbeat data packet based on the initial heartbeat interval indicated by the initial state information.
7. The method according to any one of claims 1 to 5, characterized in that: Before receiving the heartbeat data packet sent by the client, the method further includes: Receive a second handshake data packet sent by the client, where the second handshake information carried by the second handshake data packet is historical status information, and the historical status information at least includes: a historical heartbeat interval used by the client when sending a previous heartbeat data packet, and a historical status parameter of the historical heartbeat interval; Based on the historical state type represented by the historical state parameter, the second handshake information is updated to obtain the state update information, wherein the state update information at least includes: an updated heartbeat interval for the client to send a next heartbeat data packet, and an updated state parameter of the updated heartbeat interval; A second handshake reply packet carrying the status update information is returned to the client, so that the client sends the next heartbeat data packet based on the update heartbeat interval indicated by the status update information.
8. The method according to claim 7, characterized in that The historical status parameters include: the historical cumulative number of successful transmissions of the previous heartbeat data packet by the client according to the historical heartbeat interval, and the historical change stage of the historical heartbeat interval; Then, based on the historical state type represented by the historical state parameter, updating the second handshake information to obtain the state update information includes: If the historical change stage is the detection stage, and the historical cumulative number of successes is less than the second detection number threshold, the historical heartbeat interval is reduced by a preset second time interval as the update heartbeat interval, and the updated historical cumulative number of times of the update heartbeat interval is set to 0, and the update change stage of the update heartbeat interval is set to the stable stage; If the historical change stage is a stable stage and the historical cumulative number of successes is less than a second stable number threshold, the historical heartbeat interval is reduced by a preset third time interval as the update heartbeat interval, and the updated historical cumulative number of times of the update heartbeat interval is set to 0, and the update change stage in which the update heartbeat interval is located is set to a stable stage.
9. A method for adjusting heartbeat interval, characterized in that: Applied to the client, including: Sending a heartbeat data packet to the server, the heartbeat data packet carrying the current status information of the client, the status information at least including: a heartbeat interval used when sending the heartbeat data packet, and a status parameter of the heartbeat interval; Receive a response packet returned by the server, the response packet carrying state adjustment information, the state adjustment information being: the server, based on the state type represented by the state parameter, obtains the state adjustment information by using an adjustment method corresponding to the state type, the state adjustment information at least including: a target heartbeat interval for sending the next heartbeat data packet, and a target state parameter of the target heartbeat interval; The state adjustment information is used as new state information carried by the next heartbeat data packet to be sent and stored, and the next heartbeat data packet is sent to the server according to the target heartbeat interval indicated by the new state information.
10. The method according to claim 9, characterized in that Before sending the heartbeat data packet to the server, the method further includes: When establishing a connection with the server for the first time, sending a first handshake data packet to the server, wherein the first handshake information carried in the first handshake data packet is empty; Receive a first handshake reply packet returned by the server, the first handshake reply packet carrying state initial information, the state initial information being: obtained by the server initializing the first handshake information, the state initial information at least including: an initial heartbeat interval for sending a first heartbeat data packet, and an initial state parameter of the initial heartbeat interval, wherein the change stage of the initial heartbeat interval contained in the initial state parameter is the detection stage; The initial state information is used as the first state information carried by the first heartbeat data packet, and is stored; and the first heartbeat data packet is sent to the server according to the initial heartbeat interval indicated by the first state information.
11. The method according to claim 10, characterized in that Before sending the heartbeat data packet to the server, the method further includes: When it is not the first time to establish a connection with the server, sending a second handshake data packet to the server, where the second handshake information carried by the second handshake data packet is historical status information, and the historical status information at least includes: a historical heartbeat interval used when sending a previous heartbeat data packet, and a historical status parameter of the historical heartbeat interval; Receive a second handshake reply packet returned by the server, the second handshake reply packet carrying state update information, the state update information being obtained by the server updating the second handshake information based on the historical state type represented by the historical state parameter, the state update information at least including: an updated heartbeat interval for the client to send a next heartbeat data packet, and an updated state parameter of the updated heartbeat interval; The state update information is used as the second state information carried by the next heartbeat data packet to be sent and stored, and the next heartbeat data packet is sent to the server according to the update heartbeat interval indicated by the second state information.
12. A device for adjusting heartbeat interval, characterized in that: Applied to the server, including: A first receiving module is used to receive a heartbeat data packet sent by a client, wherein the heartbeat data packet carries current status information of the client, and the status information at least includes: a heartbeat interval used by the client when sending the heartbeat data packet, and a status parameter of the heartbeat interval; A first processing module is configured to adjust the state information based on the state type represented by the state parameter and adopt an adjustment method corresponding to the state type to obtain state adjustment information, wherein the state adjustment information at least includes: a target heartbeat interval for the client to send a next heartbeat data packet, and a target state parameter of the target heartbeat interval; The returning module is used to return a response packet carrying the state adjustment information to the client, so that the client sends the next heartbeat data packet based on the target heartbeat interval indicated by the state adjustment information.
13. A device for adjusting heartbeat interval, characterized in that: Applied to the client, including: A sending module, used for sending a heartbeat data packet to a server, wherein the heartbeat data packet carries the current status information of the client, and the status information at least includes: a heartbeat interval used when sending the heartbeat data packet, and a status parameter of the heartbeat interval; A second receiving module is used to receive a response packet returned by the server, wherein the response packet carries state adjustment information, wherein the state adjustment information is obtained by the server based on the state type represented by the state parameter and using an adjustment method corresponding to the state type, wherein the state adjustment information at least includes: a target heartbeat interval for sending the next heartbeat data packet, and a target state parameter of the target heartbeat interval; The second processing module is used to use the state adjustment information as new state information carried by the next heartbeat data packet to be sent, store it, and send the next heartbeat data packet to the server according to the target heartbeat interval indicated by the new state information.
14. An electronic device, characterized in that: It comprises a processor and a memory, wherein the memory stores program codes, and when the program codes are executed by the processor, the processor executes the steps of the method according to any one of claims 1 to 11.
15. A computer-readable storage medium, characterized in that: The method comprises a program code, and when the program code is run on a computing device, the program code is used to make the computing device execute the steps of the method according to any one of claims 1 to 11.