Communication method, system and related device

By using the detection connection to determine a new heartbeat cycle in the communication connection between the electronic device and the gateway, the increase in power consumption caused by frequent sending of heartbeat messages is solved, and the battery life of the device is improved.

CN119996479AActive Publication Date: 2025-05-13HUAWEI TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202510053651.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Priority Date
2023-12-29
Filing Date
2024-01-10
Publication Date
2025-05-13
Estimated Expiration
2044-01-10

AI Technical Summary

Technical Problem

In the prior art, after establishing a communication connection with the gateway, electronic devices need to frequently send heartbeat messages to avoid the connection timeout and disconnection, resulting in increased power consumption and affecting battery life.

Method used

By establishing a detection connection on the service connection, a new heartbeat cycle is determined based on the detection connection, and the transmission frequency of the heartbeat message is reduced.

Benefits of technology

It reduces the frequency of heartbeat messages sent on service connections, reduces power consumption, and improves the battery life of electronic devices.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119996479A_ABST
    Figure CN119996479A_ABST
Patent Text Reader

Abstract

The invention discloses a communication method, system and related device, the method is applied to a first electronic device, and the method comprises the following steps: the first electronic device establishes a first connection with a server; sending a first type of heartbeat message to the server based on a first period through the first connection; the first electronic device establishes a second connection with the server, wherein the second connection is used for transmitting a heartbeat message of a second type; determining a second period based on the second connection; sending a first type of heartbeat message to the server based on a second period through the first connection; and disconnecting the second connection. Therefore, the service data can be transmitted through the first connection, the second period is determined through the second connection, interruption of the service data in the detection process is avoided, the first connection can be maintained based on the determined second period, and power consumption is reduced.
Need to check novelty before this filing date? Find Prior Art

Description

[0001] This application is a divisional application. The application number of the original application is 202410045849.4, and the original application date is January 10, 2024. The entire contents of the original application are incorporated into this application by reference. Technical Field

[0002] The present application relates to the field of communications, and in particular to a communication method, system and related devices. Background Art

[0003] With the continuous development of communication technology, more and more electronic devices can be connected to the Internet through gateways and communicate with other electronic devices in the Internet.

[0004] The gateway is set with a timeout period. If the communication interval between the electronic device and the gateway exceeds the timeout period, the communication connection between the electronic device and the gateway will be disconnected. Therefore, after the electronic device establishes a communication connection with the gateway, it is necessary to frequently send heartbeat messages to the gateway to avoid the communication connection being disconnected due to timeout.

[0005] However, frequently sending heartbeat messages will cause power consumption and affect the battery life of electronic devices. Summary of the invention

[0006] The present application provides a communication method, system and related devices, which determine a new heartbeat cycle based on a detection connection, reduce the frequency of sending heartbeat messages on a service connection, reduce power consumption, and improve the endurance of an electronic device.

[0007] In a first aspect, the present application provides a communication method, applied to a first electronic device, the method comprising: the first electronic device establishes a first connection with a server; sends a first type of heartbeat message to the server based on a first period through the first connection; the first electronic device establishes a second connection with the server, the second connection is used to transmit a second type of heartbeat message; determines a second period based on the second connection; sends the first type of heartbeat message to the server based on the second period through the first connection; and disconnects the second connection.

[0008] In this way, service data can be transmitted on the first connection (ie, service connection), and the heartbeat cycle can be detected on the second connection (ie, detection connection), thereby avoiding interruption of service data transmission during the detection process.

[0009] In a possible implementation, the server is a server set, and the server includes a first server and a second server; the first server is used to establish a first connection with the first electronic device, and the second server is used to establish a second connection with the first electronic device.

[0010] In this way, different servers in the server set can provide business services and detection services respectively, which can better control data transmission on different connections.

[0011] In a possible implementation, the second period is greater than the first period.

[0012] In this way, the frequency of sending heartbeat messages on the service connection can be reduced, power consumption can be reduced, and battery life can be improved.

[0013] In one possible implementation, the first electronic device establishes a second connection with the server, specifically including: when it is detected that a detection condition is met, the first electronic device establishes a second connection with the server; wherein the detection condition includes any one or more of the following: the first electronic device establishes a communication connection with the server for the first time, the time from the last detection reaches a first time length, a first operation of the user is received, the first operation is used to instruct the first electronic device to determine the second period, and a detection instruction is received, the detection instruction is used to instruct the first electronic device to determine the second period.

[0014] In this way, when the detection condition is met, a detection connection (ie, the second connection) can be established, and the second period can be determined based on the detection connection.

[0015] In a possible implementation, the format of the heartbeat message of the first category is the same as the format of the heartbeat message of the second category; or, the format of the heartbeat message of the first category is different from the format of the heartbeat message of the second category.

[0016] In a possible implementation, the content of the first type of heartbeat message is more than that of the second type of heartbeat message. In this way, the power consumption of sending the second type of heartbeat message can be saved.

[0017] In one possible implementation, the moment when the first electronic device establishes a second connection with the server is the first moment; the second period is determined based on the second connection, specifically including: at the second moment, sending a first message to the server through the second connection, the first message is a heartbeat message of the second type, and the second moment is later than the first moment; receiving a first response, the first response is a response sent by the server through the second connection in response to the first message; when it is detected that the stop condition is met, determining the second period based on the time interval between the first moment and the second moment.

[0018] In a possible implementation manner, the second period is the time interval between the first moment and the second moment, or the second period is the difference between the time interval between the first moment and the second moment and a fourth constant.

[0019] In this way, when it is detected that the stop condition is met, the second period can be determined based on the heartbeat period corresponding to the last successful sending of the heartbeat message on the second connection.

[0020] In one possible implementation, the time interval between the first moment and the second moment is: the product of the first period and a first constant, where the first constant is a positive number greater than 1; or, the sum of the first period and a second constant, where the second constant is a positive number; or, the average value of the first period and a third constant, where the third constant is greater than the first period.

[0021] In this way, the next heartbeat cycle on the second connection can be determined based on the first cycle.

[0022] In one possible implementation, the method further includes: before the first moment, sending a second message to the server via a second connection, the second message being a heartbeat message of the second type; detecting that the second connection is disconnected; and at the first moment, the first electronic device re-establishing a second connection with the server.

[0023] In this way, after the second connection is disconnected, the second connection can be reestablished, and the second period is determined based on the reestablished second connection.

[0024] In one possible implementation, determining the second period based on the second connection specifically includes: at a third moment, sending a third message to the server through the second connection, the third message being a heartbeat message of the second type; receiving a third response, the third response being a response of the server in response to the third message sent through the second connection; at a fourth moment, sending a fourth message to the server through the second connection, the fourth message being a heartbeat message of the second type, the fourth moment being later than the third moment; receiving a fourth response, the fourth response being a response of the server in response to the fourth message sent through the second connection; and when it is detected that the stop condition is met, determining the second period based on the time interval between the third moment and the fourth moment.

[0025] In a possible implementation manner, the second period is the time interval between the third moment and the fourth moment, or the second period is the difference between the time interval between the third moment and the fourth moment and a fourth constant.

[0026] In this way, when it is detected that the stop condition is met, the second period can be determined based on the heartbeat period corresponding to the last successful sending of the heartbeat message on the second connection.

[0027] In one possible implementation, the moment when the first electronic device establishes a second connection with the server is the first moment, the time interval between the first moment and the third moment is the first time interval, and the time interval between the third moment and the fourth moment is the second time interval; the first time interval is less than the second time interval; the method also includes: before the first moment, sending a second message to the server through the second connection, the first message being a heartbeat message of the second type; detecting that the second connection is disconnected; at the first moment, the first electronic device re-establishes the second connection with the server.

[0028] In this way, after the second connection is disconnected, the second connection can be reestablished, and the second period is determined based on the reestablished second connection.

[0029] In one possible implementation, the second time interval is: the product of the first time interval and a first constant, where the first constant is a positive number greater than 1; or, the sum of the first time interval and a second constant, where the second constant is a positive number; or, the average of the first time interval and a third constant, where the third constant is greater than the first time interval.

[0030] In this way, the next heartbeat cycle of the second connection can be determined based on the current heartbeat cycle of the second connection.

[0031] In one possible implementation, before determining the second period based on the second connection, the method also includes: after receiving the third response, sending a first type of heartbeat message to the server through the first connection based on a third period, where the third period is the time interval between the first moment and the third moment.

[0032] In this way, in the process of determining the second period, the heartbeat period of the first connection can be updated in real time based on the detection result on the second connection.

[0033] In one possible implementation, before determining the second period based on the second connection, the method also includes: after receiving the third response, sending a first type of heartbeat message to the server through the first connection based on the third period, and the third period is the difference between the time interval between the first moment and the third moment and a fourth constant.

[0034] Thus, in the process of determining the second period, the heartbeat period of the first connection can be updated in real time based on the detection result on the second connection. Moreover, the heartbeat period of the first connection can be prevented from being equal to the timeout period by introducing a fixed error (ie, the fourth constant).

[0035] In one possible implementation, before the third moment, the method also includes: at the fifth moment, sending a fifth message to the server through the second connection, the fifth message being a heartbeat message of the second type; receiving a fifth response, the fifth response being a response of the server in response to the fifth message sent through the second connection; wherein the time interval between the fifth moment and the third moment is the third time interval, the time interval between the third moment and the fourth moment is the second time interval, and the third time interval is less than the second time interval.

[0036] In this way, when it is detected that the stop condition is met, the second period can be determined based on the heartbeat period corresponding to the last successful sending of the heartbeat message on the second connection.

[0037] In one possible implementation, the second time interval is: the product of the third time interval and a first constant, where the first constant is a positive number greater than 1; or, the sum of the third time interval and a second constant, where the second constant is a positive number; or, the average of the third time interval and the third constant, where the third constant is greater than the third time interval.

[0038] In this way, the next heartbeat cycle of the second connection can be determined based on the current heartbeat cycle of the second connection.

[0039] In one possible implementation, before determining the second period based on the second connection, the method also includes: after receiving the third response, sending a first type of heartbeat message to the server based on a fourth period through the first connection; the fourth period is the time interval between the fifth moment and the third moment, or the fourth period is the difference between the time interval between the fifth moment and the third moment and a fourth constant.

[0040] Thus, in the process of determining the second cycle, the heartbeat cycle of the first connection can be updated in real time based on the detection result on the second connection. In addition, the heartbeat cycle of the first connection can be prevented from being equal to the timeout period by introducing a fixed error (ie, the fourth constant).

[0041] In one possible implementation, the moment when the first electronic device establishes a second connection with the server is the first moment; the second period is determined based on the second connection, specifically including: at a sixth moment, sending a sixth message to the server through the second connection, the sixth message is a heartbeat message of the second type, and the sixth moment is later than the first moment; receiving a sixth response, the sixth response is a response of the server in response to the sixth message sent through the second connection; at a seventh moment, sending a seventh message to the server through the second connection, the seventh message is a heartbeat message of the second type, and the seventh moment is later than the sixth moment; detecting that the second connection is disconnected; when it is detected that the stop condition is met, determining the second period based on the time interval between the first moment and the sixth moment.

[0042] In a possible implementation manner, the second period is the time interval between the first moment and the sixth moment, or the second period is the difference between the time interval between the first moment and the sixth moment and a fourth constant.

[0043] In this way, when it is detected that the stop condition is met, the second period can be determined based on the heartbeat period corresponding to the last successful sending of the heartbeat message on the second connection.

[0044] In a possible implementation, determining the second period based on the second connection specifically includes: at an eighth moment, sending an eighth message to the server through the second connection, the eighth message being a heartbeat message of the second type; receiving an eighth response, the eighth response being a response of the server in response to the eighth message sent through the second connection; at a ninth moment, sending a ninth message to the server through the second connection, the ninth message being a heartbeat message of the second type, and the ninth moment being later than the eighth moment; receiving a ninth response, the ninth response being a response of the server in response to the ninth message sent through the second connection; at a tenth moment, sending a tenth message to the server through the second connection, the tenth message being a heartbeat message of the second type, and the tenth moment being later than the ninth moment; detecting that the second connection is disconnected; and when detecting that the stop condition is met, determining the second period based on the time interval between the eighth moment and the ninth moment.

[0045] In a possible implementation manner, the second period is the time interval between the eighth moment and the ninth moment, or the second period is the difference between the time interval between the eighth moment and the ninth moment and a fourth constant.

[0046] In this way, when it is detected that the stop condition is met, the second period can be determined based on the heartbeat period corresponding to the last successful sending of the heartbeat message on the second connection.

[0047] In a possible implementation, the stop condition includes any one or more of the following: the detection duration reaches a second duration, the number of second-type heartbeat messages sent through the second connection reaches a first number, and the number of second connection establishments reaches a second number.

[0048] In one possible implementation, after the first electronic device establishes a second connection with the server, the method also includes: at the eleventh moment, sending a first type of heartbeat message to the server through the first connection; at the twelfth moment, sending an eleventh message to the server through the second connection, the eleventh message is a second type of heartbeat message, the twelfth moment is later than the eleventh moment, and the time interval between the eleventh moment and the twelfth moment is a fourth time interval; at the twelfth moment, sending the first type of heartbeat message to the server through the first connection, and the absolute value of the difference between the fourth time interval and the first period is less than the first threshold.

[0049] In this way, the times of sending the heartbeat messages on the first connection and the second connection can be aligned, so as to reduce the number of times of waking up the first electronic device and reduce the power consumption of the first electronic device.

[0050] In one possible implementation, the first electronic device establishes a first connection with the server, specifically including: the first electronic device establishes a first connection with the server through the second electronic device; the first electronic device establishes a second connection with the server, specifically including: the first electronic device establishes a second connection with the server through the second electronic device.

[0051] In this way, the first electronic device can establish a communication connection with the server through the second electronic device.

[0052] In a possible implementation manner, the method further includes: the first electronic device establishing a third connection with the server; and determining the second period based on the second connection, specifically including: determining the second period based on the second connection and the third connection.

[0053] The third connection is used to transmit the second type of heartbeat message.

[0054] In this way, the second period may be determined based on a plurality of detection connections.

[0055] In a second aspect, the present application provides an electronic device, which is a first electronic device, and the first electronic device includes one or more processors and one or more memories. The one or more memories are coupled to the one or more processors, and the one or more memories are used to store computer program codes, and the computer program codes include computer instructions. When the one or more processors execute the computer instructions, the first electronic device executes the communication method in any possible implementation of any of the above aspects.

[0056] In a third aspect, an embodiment of the present application provides a readable storage medium, including instructions, which, when executed on a first electronic device, enable the first electronic device to execute a communication method in any possible implementation of any of the above aspects.

[0057] In a fourth aspect, an embodiment of the present application provides a computer program product, which, when executed on a first electronic device, enables the first electronic device to execute a communication method in any possible implementation of any of the above aspects.

[0058] The beneficial effects of the second to fourth aspects can refer to the beneficial effects of the first aspect mentioned above.

[0059] In the fifth aspect, an embodiment of the present application provides a server, which is a server set, including a first server and a second server, the first server is used to establish a first connection with a first electronic device, and the second server is used to establish a second connection with the first electronic device; the first connection is used to transmit business data and a first type of heartbeat message, and the second connection is used to transmit a second type of heartbeat message.

[0060] In this way, different servers in the server set can provide business services and detection services respectively, which can better control data transmission on different connections. BRIEF DESCRIPTION OF THE DRAWINGS

[0061] Figure 1A A schematic diagram of the relationship between an intranet, an extranet and a public network provided in an embodiment of the present application;

[0062] Figure 1B A schematic diagram of a communication connection between an electronic device A1 and a communication network C provided in an embodiment of the present application;

[0063] Figure 2A A schematic diagram of the system architecture of a communication system 10 provided in an embodiment of the present application;

[0064] Figure 2B A schematic diagram of a communication connection between an electronic device 100 and a server 300 provided in an embodiment of the present application;

[0065] Figure 3A A schematic diagram of the hardware structure of an electronic device 100 provided in an embodiment of the present application;

[0066] Figure 3B A schematic diagram of the hardware structure of a server 300 provided in an embodiment of the present application;

[0067] Figure 4 A flow chart of a communication method provided in an embodiment of the present application;

[0068] Figure 5 A schematic diagram of a process of an electronic device 100 determining a heartbeat cycle 2 based on a communication connection 2 provided in an embodiment of the present application;

[0069] Figure 6 A schematic diagram of a process of sending a service heartbeat message on a communication connection 1 by an electronic device 100 during a process of detecting a heartbeat cycle 2 provided in an embodiment of the present application;

[0070] Figure 7 A schematic diagram of the timing of sending a heartbeat message on a communication connection 1 and a communication connection 2 provided by an electronic device 100 according to an embodiment of the present application;

[0071] Figure 8 A schematic diagram of a flow chart of execution of a business server 310 and a detection server 320 in a server 300 during a detection heartbeat cycle 2 provided in an embodiment of the present application;

[0072] Fig. 9 A schematic diagram of functional modules of a communication system 10 provided in an embodiment of the present application;

[0073] Fig.10 A flow chart of a communication method provided in an embodiment of the present application. DETAILED DESCRIPTION

[0074] The technical solutions in the embodiments of the present application will be described clearly and in detail below in conjunction with the accompanying drawings. In the description of the embodiments of the present application, unless otherwise specified, " / " means or, for example, A / B can mean A or B; "and / or" in the text is only a description of the association relationship of associated objects, indicating that there can be three relationships, for example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. In addition, in the description of the embodiments of the present application, "multiple" means two or more than two.

[0075] In the following, the terms "first" and "second" are used for descriptive purposes only and are not to be understood as suggesting or implying relative importance or implicitly indicating the number of the indicated technical features. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of the features, and in the description of the embodiments of the present application, unless otherwise specified, "plurality" means two or more.

[0076] The term "user interface (UI)" in the following embodiments of the present application refers to a medium interface for interaction and information exchange between an application or operating system and a user, which realizes the conversion between the internal form of information and the form acceptable to the user. The user interface is a source code written in a specific computer language such as Java and extensible markup language (XML). The interface source code is parsed and rendered on an electronic device, and finally presented as content that can be recognized by the user. The commonly used form of user interface is a graphical user interface (GUI), which refers to a user interface related to computer operation displayed in a graphical manner. It can be a visual interface element such as text, icons, buttons, menus, tabs, text boxes, dialog boxes, status bars, navigation bars, widgets, etc. displayed on the display screen of an electronic device.

[0077] Some nouns involved in this application are introduced below.

[0078] LAN: A LAN is a communication network formed by connecting multiple electronic devices within a certain area. A LAN is a closed type and can be composed of two or more electronic devices. Through dedicated data lines, a LAN can be connected to a LAN or database in other places to form a larger information processing system.

[0079] Intranet: If an electronic device is currently in a communication network, then the communication network can be regarded as the intranet of the electronic device. Intranet belongs to local area network.

[0080] External network: If an electronic device is currently in a communication network, all other communication networks outside the communication network can be regarded as the external network of the electronic device. Generally speaking, there is a firewall between the internal network and the external network. The internal network of the firewall can be called the internal network, and the external network of the firewall can be called the external network.

[0081] Public network: The communication network that the electronic devices in the intranet can access through the gateway can be called the public network. The public network can be a local area network or a wide area network. In some application scenarios, the public network can refer to the Internet. The specific contents of the intranet, extranet and public network can also be referred to as follows Figure 1A Related description in the illustrated embodiment.

[0082] Internet Protocol Address: Internet Protocol (IP) address is a unified address format provided by IP protocol, which assigns a logical address to each network and each host on the Internet to shield the difference of physical addresses. IP protocol is a protocol designed for computer networks to connect and communicate with each other.

[0083] Intranet IP address: Intranet IP address, also known as LAN network address. Electronic devices can communicate with other electronic devices in the intranet through this intranet IP address. Intranet IP address is unique in the intranet.

[0084] Public IP address: Public IP address can be used for communication in the public network. Public IP address is unique in the public network. Since there are many electronic devices in the public network, it is unrealistic to assign a public IP address to each electronic device in the public network. Therefore, when the electronic device in the intranet accesses the public network through the gateway, the intranet IP address can be converted into a legal public IP address at the gateway, and the public network can be accessed based on the public IP address.

[0085] Network Address Translation: Network Address Translation (NAT) is a technology that converts an intranet IP address into a legitimate public IP address. NAT can connect electronic devices in the intranet to the public network and communicate with other electronic devices in the public network. NAT can not only solve the problem of insufficient public IP addresses, but also effectively avoid attacks from the external network, hiding and protecting electronic devices in the intranet.

[0086] Gateway: A gateway is a gateway that connects one communication network to another. Electronic devices in the intranet can access the public network through a gateway, and a gateway can have a NAT function. In some application scenarios, a gateway can also refer to a device with a NAT function. It should be noted that electronic devices with a NAT function, such as routers and computers, can be considered gateways.

[0087] Timeout: The timeout (aging-time) can also be called the aging time. When an electronic device in the intranet accesses the public network through the gateway, the gateway will configure a legal public IP address for the electronic device through NAT technology. However, this public IP address has a timeout. When the public IP address is not used for a period of time exceeding the timeout, the gateway will age the public IP address. At this time, the electronic device can no longer use the public IP address to access the public network.

[0088] Heartbeat message: A heartbeat message refers to data that is transmitted multiple times on a communication connection and is used to maintain the communication connection. When an intranet electronic device accesses the public network through a gateway, the intranet electronic device can establish a communication connection with a device in the public network through the gateway. According to the relevant content of the above timeout time, if the public network IP address ages, the communication connection between the electronic device and the public network is disconnected. Therefore, in order to maintain the communication connection, the electronic device needs to send heartbeat messages multiple times on the communication connection to avoid aging of the public network IP address, thereby avoiding disconnection of the communication connection. In some application scenarios, a heartbeat message may also be referred to as a heartbeat packet.

[0089] Heartbeat cycle: On a communication connection, an electronic device can send heartbeat messages at fixed time intervals, which can be called the heartbeat cycle of the communication connection. It should be noted that the heartbeat cycle on the communication connection can be changed, that is, the heartbeat cycle on the communication connection can be different in different time periods.

[0090] Low power consumption state: Low power consumption state refers to a state in which the power consumption of an electronic device is lower than the normal power consumption. In the low power consumption state, the power consumption of the central processing unit (CPU) or the microcontroller unit (MCU) is low, and the CPU (or MCU) needs to be awakened before it can work normally. When an electronic device sends or receives a heartbeat message, the electronic device can wake up the CPU (or MCU) and switch the electronic device from a low power consumption state to a working state. In an embodiment of the present application, waking up an electronic device means switching the electronic device from a low power consumption state to a working state.

[0091] Working state: Working state refers to the state in which the power consumption of the electronic device is maintained at normal power consumption. In the working state, the CPU (or MCU) can work normally.

[0092] The following describes the relationship between the intranet, extranet and public network with specific examples.

[0093] Figure 1A A schematic diagram showing the relationship between an intranet, an extranet and a public network is shown.

[0094] like Figure 1A As shown, communication network A may include electronic device A1 and electronic device A2, communication network B may include electronic device B1 and electronic device B2, communication network C may include electronic device C1 and electronic device C2, and communication network C may also include communication network A and communication network B. Wherein:

[0095] Communication network A can be regarded as the intranet of electronic device A1 and electronic device A2, communication network B can be regarded as the extranet of electronic device A1 and electronic device A2, and communication network C can be regarded as the public network of communication network A. Electronic device A2 can establish a communication connection with communication network C as a gateway, so that electronic device A1 can communicate with electronic devices in communication network C (such as electronic device C1, electronic device C2, electronic devices in communication network B, etc.) through electronic device A2.

[0096] Communication network B can be regarded as the intranet of electronic device B1 and electronic device B2, communication network A can be regarded as the extranet of electronic device B1 and electronic device B2, and communication network C can be regarded as the public network of communication network B. Electronic device B1 can establish a communication connection with communication network C as a gateway, so that electronic device B2 can communicate with electronic devices in communication network C (such as electronic device C1, electronic device C2, electronic devices in communication network A, etc.) through electronic device B1.

[0097] Understandably, Figure 1A The illustrated embodiments are merely illustrative of the relationship between the intranet, extranet and public network. In the embodiments of the present application, each communication network may also include more or fewer electronic devices than in the above embodiments, or include more, fewer or different communication networks than in the above embodiments, and the present application does not make any limitation thereto.

[0098] The following describes how electronic devices in the intranet communicate with electronic devices in the public network through a gateway.

[0099] Figure 1B A schematic diagram of the communication connection between the electronic device A1 and the communication network C is shown.

[0100] like Figure 1BAs shown, electronic device A1 and electronic device A2 belong to communication network A. Communication network A and communication network C can refer to the above Figure 1A Related descriptions in the illustrated embodiments. Among them, the electronic device A2 can be used as a gateway, so that the electronic device A1 is connected to the communication network C through the electronic device A2.

[0101] Electronic device A1 may have an intranet IP address, and electronic device A1 may establish a communication connection with electronic device A2 based on the intranet IP address. Electronic device A2 has a NAT function and may configure a public IP address for electronic device A1. Based on the public IP address, electronic device A1 may establish a communication connection with any device in communication network C through electronic device A2.

[0102] According to the above timeout period, the public IP address configured by electronic device A2 for electronic device A1 has a timeout period. In the case of no timeout, electronic device A2 can maintain the communication connection between electronic device A1 and communication network C. At this time, electronic device A1 can communicate with communication network C through electronic device A2 based on the public IP address; in the case of timeout, electronic device A2 can age the public IP address originally configured for electronic device A1. At this time, electronic device A1 cannot communicate with communication network C through electronic device A2 based on the original public IP address. After the timeout, if electronic device A1 still needs to communicate with devices in communication network C, electronic device A2 can assign a new public IP address to electronic device A1 and establish a communication connection with devices in communication network C based on the newly assigned public IP address.

[0103] It is understandable that, in the case of business data interaction between the electronic device A1 and the devices in the communication network C, if the communication connection between the electronic device A1 and the communication network C is disconnected, the transmission of business data between the electronic device A1 and the communication network C will be affected. The electronic device A1 can send multiple heartbeat messages through the communication connection to maintain the communication connection between the electronic device A1 and the communication network C. When the transmission interval between any two adjacent data (such as business data, heartbeat messages, etc.) on the communication connection is less than the timeout period, the communication connection can be prevented from being disconnected.

[0104] In some embodiments, the electronic device A1 can set a heartbeat period for the communication connection, and the heartbeat period can be less than the timeout period. The electronic device A1 can send a heartbeat message to the communication network C through the communication connection at a fixed time interval based on the heartbeat period. In this way, even if the communication connection does not transmit business data for a period of time, the electronic device A2 can maintain the communication connection between the electronic device A1 and the communication network C based on the heartbeat message.

[0105] It should be noted that if the electronic device A1 is in a low power consumption state, each time the electronic device A1 sends or receives a heartbeat message, the electronic device A1 will switch from the low power consumption state to the working state, and the power consumption required for the electronic device A1 to switch from the low power consumption state to the working state is relatively large. It is understandable that the smaller the heartbeat cycle, the more times the electronic device A1 sends heartbeat messages in the same time period, the greater the power consumption of the electronic device A1, and the worse the battery life.

[0106] Therefore, the electronic device A1 needs to determine a heartbeat cycle that is shorter than the timeout period and has the smallest difference with the timeout period, so as to reduce the power consumption of the electronic device A1 while maintaining the communication connection.

[0107] In some embodiments, the electronic device A1 may be provided with a detection step length (e.g., 30 seconds, 1 minute, etc.). When the electronic device A1 establishes a communication connection with the communication network C, the electronic device A1 may determine a new heartbeat cycle based on the sum of the current heartbeat cycle and the detection step length, and judge whether the updated heartbeat cycle can maintain the communication connection based on whether each heartbeat message is successfully sent, until the largest heartbeat cycle that can maintain the communication connection is detected, and a heartbeat message is sent based on the detected heartbeat cycle to maintain the communication connection. In this way, the heartbeat cycle on the communication connection increases, and the frequency of sending heartbeat messages decreases, which can reduce the power consumption of the electronic device A1 and avoid the disconnection of the communication connection. However, in the process of detecting the largest heartbeat cycle that can maintain the communication connection, the communication connection may be disconnected, which will affect the transmission of business data.

[0108] The following introduces the system architecture of a communication system 10 provided in an embodiment of the present application.

[0109] Figure 2A A schematic diagram of the system architecture of a communication system 10 provided in an embodiment of the present application is shown.

[0110] like Figure 2A As shown, the communication system 10 may include an electronic device 100, an electronic device 200 and a server 300. Among them:

[0111] One or more communication connections, such as communication connection A1 and communication connection A2, may be established between the electronic device 100 and the electronic device 200. One or more communication connections, such as communication connection B1 and communication connection B2, may be established between the electronic device 200 and the server 300.

[0112] The electronic device 100 may establish one or more communication connections with the server 300, such as communication connection 1 and communication connection 2. Communication connection 1 and communication connection 2 are communication connections between the electronic device 100 and the server 300. Among them, communication connection 1 may include the above-mentioned communication connection A1 and communication connection B1, and communication connection 2 may include the above-mentioned communication connection A2 and communication connection B2.

[0113] Communication connection 1 can be used to transmit business data between electronic device 100 and server 300, and electronic device 100 can perform corresponding business based on the transmitted business data, such as video playback business, audio playback business, page browsing business, call business, game business, etc. Therefore, in the embodiment of the present application, the communication connection used to transmit business data can also be referred to as a business connection, and communication connection 1 belongs to a business connection. Communication connection 1 can also be used to transmit business heartbeat messages, and business heartbeat messages are used to maintain communication connection 1 to prevent communication connection 1 from being disconnected due to exceeding the timeout period of electronic device 200. Electronic device 100 can send business heartbeat messages to server 300 based on heartbeat cycle 1 on communication connection 1.

[0114] Communication connection 2 can be used to detect heartbeat cycle 2. In an embodiment of the present application, the communication connection used to detect heartbeat cycle 2 can also be referred to as a detection connection, and communication connection 2 belongs to the detection connection. Communication connection 2 can be used to transmit a detection heartbeat message. The detection heartbeat message is used to detect heartbeat cycle 2. The electronic device 100 can determine the heartbeat cycle 2 by changing the time interval for sending the detection heartbeat message and whether each detection heartbeat message is successfully sent. It can be understood that in the process of detecting heartbeat cycle 2, communication connection 2 may be disconnected and re-established once or more times. In other embodiments, the detection connection between the electronic device 100 and the server 300 may also include multiple communication connections. In this case, the electronic device 100 can detect the heartbeat cycle 2 through the multiple communication connections, and the present application is not limited thereto.

[0115] After determining the heartbeat cycle 2, the electronic device 100 may change the period of sending heartbeat messages on the service connection (eg, communication connection 1) to the heartbeat cycle 2, and may also disconnect the detection connection (eg, communication connection 2).

[0116] The electronic device 200 can act as a gateway to convert the intranet IP address of the electronic device 100 into a public IP address, and connect the electronic device 100 with the server 300. In other embodiments, the electronic device 200 can also connect the electronic device 100 with other electronic devices. In some embodiments, the electronic device 200 can be a router or other types of electronic devices, and the present application does not limit the device type of the electronic device 200.

[0117] In some embodiments, the server 300 may include one or more server modules, and each server module may have different functions. In other embodiments, the server 300 may also be regarded as a server cluster including multiple servers, and each server in the server cluster may have different functions, which is not limited in this application. The specific content of the server 300 may also refer to the following Figure 2B The relevant descriptions in the illustrated embodiments are not described in detail here.

[0118] It is understandable that the above Figure 2A The embodiment shown is only an example. In some embodiments, more devices (such as routers, etc.) may be included between the electronic device 100 and the server 300, which is not limited in this application. In addition, the communication system 10 may also include more electronic devices or electronic devices of different types from those in the above embodiment, which is not limited in this application.

[0119] Figure 2B A schematic diagram of a communication connection between an electronic device 100 and a server 300 provided in an embodiment of the present application is shown.

[0120] like Figure 2B As shown, the server 300 may include a service server 310 and a detection server 320 .

[0121] In some embodiments, the server 300 may include multiple server modules. In this case, the business server 310 may be one or more server modules in the server 300 , and the detection server 320 may also be one or more server modules in the server 300 .

[0122] In other embodiments, the server 300 may be a server cluster including multiple servers. In this case, the business server 310 may be one or more servers in the server cluster, and the detection server 320 may also be one or more servers in the server cluster.

[0123] In the server 300, the service server 310 can provide service services for the electronic device 100, and the service server 300 can establish a service connection with the electronic device 100 through the electronic device 200 (for example, the above Figure 2A The communication connection 1) in the embodiment shown in the figure is used to send and receive service data through the service connection, so that the electronic device 100 can perform corresponding services, such as video playback services, audio playback services, call services, game services, page browsing services, etc. The detection server 320 can establish one or more detection connections with the electronic device 100 through the electronic device 200, such as the above Figure 2A The communication connection 2 in the illustrated embodiment. The electronic device 100 may determine the heartbeat cycle 2 based on the one or more detection connections.

[0124] In this way, different server modules in the server 300 can provide business services and detection services to the electronic device 100 respectively, and the detection service can be isolated from the business service, so that the server 300 can better control the data transmission on the business connection and the detection connection.

[0125] It is understandable that the above Figure 2B The embodiment shown is only an example. In the embodiment of the present application, the server 300 may also include Figure 2B The illustrated embodiments may have more, fewer, or different server modules (or servers) than those described above, and this application does not limit this.

[0126] It should be noted that in some other embodiments, the server 300 may not include the detection server 320. In this case, the business server 310 can establish a business connection and a detection connection with the electronic device 100 through the electronic device 200. The business server 310 can control the business connection to send and receive business data, and control the detection connection to receive the detection heartbeat message sent by the electronic device 100.

[0127] The following introduces the hardware structure of an electronic device 100 provided in an embodiment of the present application.

[0128] Figure 3A A schematic diagram of the hardware structure of an electronic device 100 provided in an embodiment of the present application is shown.

[0129] The electronic device 100 may be a mobile phone, a tablet computer, a desktop computer, a laptop computer, a handheld computer, a notebook computer, an ultra-mobile personal computer (UMPC), a netbook, a cellular phone, a personal digital assistant (PDA), an augmented reality (AR) device, a virtual reality (VR) device, an artificial intelligence (AI) device, a wearable device, an in-vehicle device, a smart home device and / or a smart city device. The embodiments of the present application do not impose any special restrictions on the specific type of the electronic device.

[0130] The electronic device 100 may include a processor 110, an external memory interface 120, an internal memory 121, a universal serial bus (USB) interface 130, a charging management module 140, a power management module 141, a battery 142, an antenna 1, an antenna 2, a mobile communication module 150, a wireless communication module 160, etc. Optionally, the electronic device 100 may also include any one or more of the following: an audio module 170, a sensor module 180, a button 190, a motor 191, an indicator 192, a display screen 194, etc. The sensor module 180 may include a touch sensor 180K. Optionally, the sensor module 180 may also include any one or more of the following: a pressure sensor, a gyroscope sensor, an air pressure sensor, a magnetic sensor, an acceleration sensor, a distance sensor, a proximity light sensor, a fingerprint sensor, a temperature sensor, an ambient light sensor, a bone conduction sensor, etc.

[0131] It is to be understood that the structure illustrated in the embodiment of the present invention does not constitute a specific limitation on the electronic device 100. In other embodiments of the present application, the electronic device 100 may include more or fewer components than shown in the figure, or combine some components, or separate some components, or arrange the components differently. The components shown in the figure may be implemented in hardware, software, or a combination of software and hardware.

[0132] The processor 110 may include one or more processing units, for example, the processor 110 may include an application processor (AP), a modem processor, a graphics processor (GPU), an image signal processor (ISP), a controller, a video codec, a digital signal processor (DSP), a baseband processor, and / or a neural-network processing unit (NPU), etc. Different processing units may be independent devices or integrated into one or more processors.

[0133] The controller can generate operation control signals according to the instruction operation code and timing signal to complete the control of instruction fetching and execution.

[0134] The processor 110 may also be provided with a memory for storing instructions and data. In some embodiments, the memory in the processor 110 is a cache memory. The memory may store instructions or data that the processor 110 has just used or cyclically used. If the processor 110 needs to use the instruction or data again, it may be directly called from the memory. This avoids repeated access, reduces the waiting time of the processor 110, and thus improves the efficiency of the system.

[0135] In some embodiments, the processor 110 may include one or more interfaces. The interface may include an inter-integrated circuit (I2C) interface, an inter-integrated circuit sound (I2S) interface, a pulse code modulation (PCM) interface, a universal asynchronous receiver / transmitter (UART) interface, a mobile industry processor interface (MIPI), a general-purpose input / output (GPIO) interface, a subscriber identity module (SIM) interface, and / or a universal serial bus (USB) interface, etc.

[0136] The charging management module 140 is used to receive charging input from a charger. The charger may be a wireless charger or a wired charger. In some wired charging embodiments, the charging management module 140 may receive charging input from a wired charger through the USB interface 130. In some wireless charging embodiments, the charging management module 140 may receive wireless charging input through a wireless charging coil of the electronic device 100. While the charging management module 140 is charging the battery 142, it may also power the electronic device through the power management module 141.

[0137] The power management module 141 is used to connect the battery 142, the charging management module 140 and the processor 110. The power management module 141 receives input from the battery 142 and / or the charging management module 140, and provides power to the processor 110, the internal memory 121, the display screen 194 and the wireless communication module 160. The power management module 141 can also be used to monitor parameters such as battery capacity, battery cycle number, battery health status (leakage, impedance), etc. In some other embodiments, the power management module 141 can also be set in the processor 110. In other embodiments, the power management module 141 and the charging management module 140 can also be set in the same device.

[0138] The wireless communication function of the electronic device 100 can be implemented through the antenna 1, the antenna 2, the mobile communication module 150, the wireless communication module 160, the modem processor and the baseband processor.

[0139] Antenna 1 and antenna 2 are used to transmit and receive electromagnetic wave signals. Each antenna in electronic device 100 can be used to cover a single or multiple communication frequency bands. Different antennas can also be reused to improve the utilization of antennas. For example, antenna 1 can be reused as a diversity antenna for a wireless local area network. In some other embodiments, the antenna can be used in combination with a tuning switch.

[0140] The mobile communication module 150 can provide solutions for wireless communications including 2G / 3G / 4G / 5G, etc., applied to the electronic device 100. The mobile communication module 150 may include at least one filter, a switch, a power amplifier, a low noise amplifier (LNA), etc. The mobile communication module 150 can receive electromagnetic waves from the antenna 1, and filter, amplify, and process the received electromagnetic waves, and transmit them to the modulation and demodulation processor for demodulation. The mobile communication module 150 can also amplify the signal modulated by the modulation and demodulation processor, and convert it into electromagnetic waves for radiation through the antenna 1. In some embodiments, at least some of the functional modules of the mobile communication module 150 can be set in the processor 110. In some embodiments, at least some of the functional modules of the mobile communication module 150 can be set in the same device as at least some of the modules of the processor 110.

[0141] The modem processor may include a modulator and a demodulator. Among them, the modulator is used to modulate the low-frequency baseband signal to be sent into a medium-high frequency signal. The demodulator is used to demodulate the received electromagnetic wave signal into a low-frequency baseband signal. The demodulator then transmits the demodulated low-frequency baseband signal to the baseband processor for processing. After the low-frequency baseband signal is processed by the baseband processor, it is passed to the application processor. The application processor outputs a sound signal through an audio device (not limited to a speaker 170A, a receiver 170B, etc.), or displays an image or video through a display screen 194. In some embodiments, the modem processor may be an independent device. In other embodiments, the modem processor may be independent of the processor 110 and be set in the same device as the mobile communication module 150 or other functional modules.

[0142] The wireless communication module 160 can provide wireless communication solutions including wireless local area networks (WLAN) (such as wireless fidelity (Wi-Fi) networks), bluetooth (BT), global navigation satellite system (GNSS), frequency modulation (FM), near field communication (NFC), infrared (IR), etc., which are applied to the electronic device 100. The wireless communication module 160 can be one or more devices integrating at least one communication processing module. The wireless communication module 160 receives electromagnetic waves via the antenna 2, demodulates and filters the electromagnetic wave signals, and sends the processed signals to the processor 110. The wireless communication module 160 can also receive the signal to be sent from the processor 110, modulate the frequency, amplify it, and convert it into electromagnetic waves for radiation through the antenna 2.

[0143] In some embodiments, the antenna 1 of the electronic device 100 is coupled to the mobile communication module 150, and the antenna 2 is coupled to the wireless communication module 160, so that the electronic device 100 can communicate with the network and other devices through wireless communication technology. The wireless communication technology may include global system for mobile communications (GSM), general packet radio service (GPRS), code division multiple access (CDMA), wideband code division multiple access (WCDMA), time-division code division multiple access (TD-SCDMA), long term evolution (LTE), BT, GNSS, WLAN, NFC, FM, and / or IR technology. The GNSS may include a global positioning system (GPS), a global navigation satellite system (GLONASS), a Beidou navigation satellite system (BDS), a quasi-zenith satellite system (QZSS) and / or a satellite based augmentation system (SBAS).

[0144] The electronic device 100 implements the display function through a GPU, a display screen 194, and an application processor. The GPU is a microprocessor for image processing, which connects the display screen 194 and the application processor. The GPU is used to perform mathematical and geometric calculations for graphics rendering. The processor 110 may include one or more GPUs that execute program instructions to generate or change display information.

[0145] The display screen 194 is used to display images, videos, etc. The display screen 194 includes a display panel. The display panel can be a liquid crystal display (LCD), and the display panel can also be made of an organic light-emitting diode (OLED), an active-matrix organic light-emitting diode or an active-matrix organic light-emitting diode (AMOLED), a flexible light-emitting diode (FLED), Miniled, MicroLed, Micro-oLed, quantum dot light emitting diodes (QLED), etc. In some embodiments, the electronic device 100 may include 1 or N display screens 194, where N is a positive integer greater than 1.

[0146] The internal memory 121 may include one or more random access memories (RAM) and one or more non-volatile memories (NVM).

[0147] The random access memory can be directly read and written by the processor 110, and can be used to store executable programs (such as machine instructions) of the operating system or other running programs, and can also be used to store user and application data.

[0148] The non-volatile memory may also store executable programs and user and application data, etc., and may be loaded into the random access memory in advance for direct reading and writing by the processor 110 .

[0149] The external memory interface 120 can be used to connect to an external non-volatile memory to expand the storage capacity of the electronic device 100. The external non-volatile memory communicates with the processor 110 through the external memory interface 120 to implement a data storage function. For example, files such as music and videos are stored in the external non-volatile memory.

[0150] The audio module 170 may include any one or more of the following: a speaker 170A, a receiver 170B, a microphone 170C, etc. In some embodiments, the electronic device 100 may implement audio functions such as music playback and recording through the audio module 170 and an application processor, etc.

[0151] The audio module 170 is used to convert digital audio information into analog audio signal output, and is also used to convert analog audio input into digital audio signals. The audio module 170 can also be used to encode and decode audio signals. In some embodiments, the audio module 170 can be arranged in the processor 110, or some functional modules of the audio module 170 can be arranged in the processor 110.

[0152] The speaker 170A, also called a "speaker", is used to convert an audio electrical signal into a sound signal. The electronic device 100 can listen to music or listen to a hands-free call through the speaker 170A.

[0153] The receiver 170B, also called a "earpiece", is used to convert audio electrical signals into sound signals. When the electronic device 100 receives a call or voice message, the voice can be received by placing the receiver 170B close to the human ear.

[0154] Microphone 170C, also called "microphone" or "microphone", is used to convert sound signals into electrical signals. When making a call or sending a voice message, the user can speak by putting their mouth close to microphone 170C to input the sound signal into microphone 170C. The electronic device 100 can be provided with at least one microphone 170C. In other embodiments, the electronic device 100 can be provided with two microphones 170C, which can not only collect sound signals but also realize noise reduction function. In other embodiments, the electronic device 100 can also be provided with three, four or more microphones 170C to collect sound signals, reduce noise, identify the sound source, realize directional recording function, etc.

[0155] The touch sensor 180K is also called a "touch control device". The touch sensor 180K can be set on the display screen 194. The touch sensor 180K and the display screen 194 form a touch screen, also called a "touch control screen". The touch sensor 180K is used to detect touch operations acting on or near it. The touch sensor can pass the detected touch operation to the application processor to determine the type of touch event. Visual output related to the touch operation can be provided through the display screen 194. In other embodiments, the touch sensor 180K can also be set on the surface of the electronic device 100, which is different from the position of the display screen 194.

[0156] The key 190 includes a power key, a volume key, etc. The key 190 may be a mechanical key or a touch key. The electronic device 100 may receive key input and generate key signal input related to user settings and function control of the electronic device 100.

[0157] Motor 191 can generate vibration prompts. Motor 191 can be used for incoming call vibration prompts, and can also be used for touch vibration feedback. For example, touch operations acting on different applications (such as taking pictures, audio playback, etc.) can correspond to different vibration feedback effects. For touch operations acting on different areas of the display screen 194, motor 191 can also correspond to different vibration feedback effects. Different application scenarios (for example: time reminders, receiving messages, alarm clocks, games, etc.) can also correspond to different vibration feedback effects. The touch vibration feedback effect can also support customization.

[0158] Indicator 192 may be an indicator light, which may be used to indicate charging status, power changes, messages, missed calls, notifications, etc.

[0159] It is understandable that in some embodiments, the hardware structure of the electronic device 200 may also refer to Figure 3A The hardware structure of the electronic device 100 shown in FIG. 1 may include a hardware structure of the electronic device 100 shown in FIG. 100 . In other embodiments, the electronic device 200 may include a hardware structure of the electronic device 100 shown in FIG. Figure 3A The present application does not limit the devices in the illustrated embodiment to fewer, more or different devices from the above-mentioned embodiments.

[0160] Figure 3B A schematic diagram of the hardware structure of a server 300 provided in an embodiment of the present application.

[0161] like Figure 3B As shown, the server 300 may include: one or more network device processors 301, a memory 302, a communication interface 303, a transmitter 305, a receiver 306, a coupler 307 and an antenna 308. These components may be connected via a bus 304 or other means. Figure 3B Take bus connection as an example.

[0162] The communication interface 303 can be used for the server 300 to communicate with other communication devices, such as electronic devices used by consumers of the project. Specifically, the communication interface 303 can be a 3G communication interface, a long-term evolution (LTE) (4G) communication interface, a 5G communication interface, a WLAN communication interface, a WAN communication interface, etc. Not limited to a wireless communication interface, the server 300 can also be configured with a wired communication interface 303 to support wired communication.

[0163] In some embodiments of the present application, the transmitter 305 and the receiver 306 can be regarded as a wireless modem. The transmitter 305 can be used to transmit and process the signal output by the network device processor 301. The receiver 306 can be used to receive the signal. In the server 300, the number of the transmitter 305 and the receiver 306 can be one or more. The antenna 308 can be used to convert the electromagnetic energy in the transmission line into electromagnetic waves in the free space, or to convert the electromagnetic waves in the free space into electromagnetic energy in the transmission line. The coupler 307 can be used to divide the mobile communication signal into multiple paths and distribute it to multiple receivers 306. It can be understood that the antenna 308 of the network device can be implemented as a large-scale antenna array.

[0164] The memory 302 is coupled to the network device processor 301 and is used to store various software programs and / or multiple sets of instructions. Specifically, the memory 302 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more disk storage devices, flash memory devices or other non-volatile solid-state storage devices.

[0165] The memory 302 may store an operating system (hereinafter referred to as system), such as an embedded operating system such as uCOS, VxWorks, RTLinux, etc. The memory 302 may also store a network communication program, which may be used to communicate with other communication devices.

[0166] In the embodiment of the present application, the network device processor 301 can be used to read and execute computer-readable instructions. Specifically, the network device processor 301 can be used to call a program stored in the memory 302, such as an implementation program of the communication method provided in one or more embodiments of the present application, and execute the instructions contained in the program.

[0167] Understandably, Figure 3B The embodiment shown is only an example. In the embodiment of the present application, the server 300 may also include more, less or different components than the above embodiment, and the present application does not limit this. It should be noted that in other embodiments, the hardware structure of a server module in the server 300 (or a server in the server cluster corresponding to the server 300) may also refer to the above Figure 3B The relevant description in the illustrated embodiment will not be repeated here.

[0168] The present application provides a communication method, in which an electronic device 100 can establish a communication connection 1 with a server 300, and the electronic device 100 can interact with the server 300 for business data based on the communication connection 1. The electronic device 100 sends a business heartbeat message to the server 300 based on the heartbeat cycle 1 in the communication connection 1. The electronic device 100 can also establish a communication connection 2 with the server 300, and send a detection heartbeat message to the server 300 through the communication connection 2. The electronic device 100 can determine the heartbeat cycle 2 based on the communication connection 2. After determining the heartbeat cycle 2, the electronic device 100 can send a business heartbeat message to the server 300 based on the heartbeat cycle 2 on the communication connection 1, and disconnect the communication connection 2.

[0169] In this way, the electronic device 100 can maintain the communication connection 1 based on the heartbeat cycle 2 determined on the communication connection 2, thereby reducing the power consumption caused by the sending of the heartbeat message. Moreover, in the process of determining the heartbeat cycle 2, the communication connection 1 is always connected, and the business data is transmitted on the communication connection 1, which can avoid the interruption of the business data during the detection process.

[0170] Figure 4 A flow chart of a communication method provided in an embodiment of the present application is shown.

[0171] like Figure 4 As shown, the specific process of the communication method may include the following steps:

[0172] S401. The electronic device 100 establishes a communication connection 1 with the server 300, and the electronic device 100 sends a service heartbeat message to the server 300 through the communication connection 1 based on the heartbeat cycle 1.

[0173] In some embodiments, the specific method for the electronic device 100 to establish a communication connection (eg, communication connection 1, communication connection 2, etc.) with the server 300 may refer to the method for establishing a TCP long link, which will not be described in detail in this application.

[0174] The electronic device 100 can establish a communication connection 1 with the server 300 through the electronic device 200. The communication connection 1 can be used to send and receive service data so that the electronic device 100 can perform corresponding services (such as video playback services, audio playback services, page browsing services, chat services, game services, etc.).

[0175] In an embodiment of the present application, the heartbeat message sent on communication connection 1 can be called a service heartbeat message, and the heartbeat message sent on communication connection 2 (or other detection connection) can be called a detection heartbeat message.

[0176] The following describes the content of the business heartbeat message and the detection heartbeat message.

[0177] Exemplarily, Table 1 shows the content composition of a service heartbeat message sent on a service connection and a detection heartbeat message sent on a detection connection.

[0178] Table 1

[0179]

[0180] As shown in Table 1, the service heartbeat message sent on the service connection may include the following contents: encryption protocol, device registration information, authentication information, key information, heartbeat message identification number, etc. The detection heartbeat message sent on the detection connection may include the heartbeat message identification number, and optionally, may also include the encryption protocol. Among them, the encryption protocol is used to indicate the encryption protocol of the data in the heartbeat message. The device registration information is used to indicate that the sending device of the heartbeat message is the electronic device 100. The authentication information can be used to indicate the authority of the electronic device 100, for example, to indicate whether the electronic device 100 has the authority to obtain the service data of the server 300. The key information may include the key of the heartbeat message. For example, in the service heartbeat message, the key information and the encryption protocol can be used to decrypt the service heartbeat message. The heartbeat message identification number can be used to indicate the number of fields of the heartbeat message. As can be seen from Table 1, the number of fields in the service heartbeat message can be M1, and the number of fields in the detection heartbeat message can be M2. M1 can be greater than or equal to M2. Exemplarily, M1 can be 3 and M2 can be 1.

[0181] It is understandable that the embodiment shown in Table 1 is only an example. In other embodiments, the service heartbeat message and the detection heartbeat message may also include more, less or different content than the above embodiment, and the present application does not limit this.

[0182] In other embodiments, the content composition of the detection heartbeat message may also be the same as the content composition of the service heartbeat message, and this application does not limit this.

[0183] It should be noted that after the electronic device 100 establishes the communication connection 1 with the server 300 , in order to maintain the communication connection 1 , the electronic device 100 may send multiple service heartbeat messages to the server 300 through the communication connection.

[0184] Heartbeat cycle 1 can be a preset time length, such as 5 seconds, 30 seconds, 3 minutes, 5 minutes, etc.

[0185] In some embodiments, after establishing the communication connection 1, the electronic device 100 can send a service heartbeat message to the server 300 at a fixed time interval through the communication connection 1, thereby avoiding disconnection of the communication connection 1. The fixed time interval is the time length corresponding to the heartbeat cycle 1.

[0186] In other embodiments, after establishing communication connection 1, electronic device 100 may first send a service heartbeat message based on heartbeat cycle 1, then update the heartbeat cycle of communication connection 1 based on subsequent detection results on communication connection 2, and send a service heartbeat message based on the updated heartbeat cycle. The updating method of the heartbeat cycle of communication connection 1 can refer to the following Figure 6 The relevant descriptions in the illustrated embodiments are not described in detail here.

[0187] S402. When the detection condition is met, the electronic device 100 establishes a communication connection 2 with the server 300.

[0188] The detection conditions may include but are not limited to any one or more of the following: the electronic device 100 is connected to a communication network for the first time, the time since the electronic device 100 last detected a heartbeat cycle reaches a preset time (for example, 5 days, 10 days or 14 days, etc.), the electronic device 100 receives an operation from the user to detect a heartbeat cycle, the electronic device 100 receives a detection instruction sent by other electronic devices, and the detection instruction is used to instruct the electronic device 100 to detect a heartbeat cycle, etc.

[0189] When the electronic device 100 detects that the detection condition is met, the electronic device 200 may establish one or more detection connections with the server 300 , and the one or more detection connections may be used to detect the heartbeat cycle 2 .

[0190] In some embodiments, the one or more probing connections may include communication connection 2 .

[0191] In other embodiments, the one or more detection connections may also include communication connection 2 and other communication connections, which is not limited in the present application.

[0192] S403 . The electronic device 100 determines the heartbeat cycle 2 based on the communication connection 2 .

[0193] The electronic device 100 can determine the heartbeat cycle 2 on the communication connection 2 by using any method such as binary division method, step-by-step detection method, exponential detection method, etc.

[0194] For example, Figure 5 A schematic diagram of a process of an electronic device 100 determining a heartbeat cycle 2 based on a communication connection 2 provided in an embodiment of the present application is shown.

[0195] S501. The electronic device 100 determines a detection interval, where the detection interval includes an upper detection limit and / or a lower detection limit.

[0196] The electronic device 100 may first determine a detection interval, which may include an upper detection limit and / or a lower detection limit.

[0197] In some embodiments, the electronic device 100 may determine the detection lower limit of the detection interval based on the heartbeat cycle 1 in step S401. For example, if the heartbeat cycle 1 is T0, the detection lower limit is determined to be T0. After determining the detection lower limit, the electronic device 100 may determine the detection interval to be [T0, +∞], or determine the detection interval to be [T0, K*T0], where K is a preset positive number.

[0198] It is understandable that this is just an example. In the embodiment of the present application, the electronic device 100 can also determine the detection interval based on other preset time thresholds, or determine a detection interval different from the above embodiment in a manner different from the above embodiment. The present application does not limit this.

[0199] S502. The electronic device 100 updates the heartbeat period of the communication connection 2 based on the detection interval, and the value of the heartbeat period belongs to the detection interval.

[0200] The detection interval includes an upper detection limit and / or a lower detection limit. The electronic device 100 can determine the heartbeat period of the communication connection 2 based on the upper detection limit and / or the lower detection limit. Exemplarily, the electronic device 100 can calculate the heartbeat period of the communication connection 2 using any one of the following formulas (1) to (3).

[0201] Heartbeat cycle = (detection upper limit + detection lower limit) / 2 Formula (1)

[0202] In the above formula (1), the heartbeat period may be the average value of the detection upper limit and the detection lower limit.

[0203] Heartbeat cycle = detection lower limit + step length formula (2)

[0204] In the above formula (2), the heartbeat period may be the sum of the detection lower limit and the step length, wherein the step length may be a preset time length (eg, 30 seconds, 60 seconds, etc.).

[0205] Heartbeat cycle = detection lower limit * a formula (3)

[0206] In the above formula (3), the heartbeat period may be the product of the detection lower limit and a constant a, and the constant a is a positive number greater than 1.

[0207] It is understandable that the embodiments here are just three examples. In other embodiments, the electronic device 100 may also determine the heartbeat period of the communication connection 2 in a manner different from the above embodiments, and the present application does not limit this.

[0208] It should be noted that steps S502 to S508 are steps that can be repeatedly executed. In some embodiments, the electronic device 100 can update the heartbeat period of the communication connection 2 in the same manner each time step S502 is executed, for example, the heartbeat period of the communication connection 2 is updated in the manner shown in the above formula (1). In other embodiments, the electronic device 100 can also update the heartbeat period of the communication connection 2 in a different manner each time step S502 is executed, for example, the heartbeat period of the communication connection 2 is updated in the manner shown in formula (3) when step S502 is executed for the first time, and the heartbeat period of the communication connection 2 is updated in the manner shown in formula (1) when step S502 is executed for the second time, etc. It can be understood that the embodiments here are only exemplary, and the updating manner of the heartbeat period of the communication connection 2 can be the same or different each time step S502 is executed, and the present application does not limit it here.

[0209] S503. The electronic device 100 determines the next heartbeat time based on the heartbeat cycle of the communication connection 2.

[0210] exist Figure 5 In the illustrated embodiment, the next heartbeat time refers to the next sending time of the detection heartbeat message.

[0211] The electronic device 100 can determine the time of the next heartbeat based on the following formula (4).

[0212] Next heartbeat time = heartbeat cycle + last heartbeat time formula (4)

[0213] In the above formula (4), the next heartbeat time can be determined based on the heartbeat cycle and the previous heartbeat time.

[0214] It should be noted that if the next heartbeat is the first heartbeat, the time of the previous heartbeat may be replaced by the time when the communication connection 2 is established.

[0215] S504. When the next heartbeat time arrives, the electronic device 100 sends a detection heartbeat message through the communication connection 2.

[0216] For the specific content of the detection heartbeat message, reference may be made to the relevant description in the embodiment shown in Table 1 above.

[0217] In some embodiments, the detection heartbeat message may also include heartbeat time information (such as the next heartbeat cycle, etc.), and the heartbeat time information is used to determine a heartbeat time after the current heartbeat time. This application is not limited here, and specific reference may be made to the following Figure 8 The relevant descriptions in the illustrated embodiments are not described in detail here.

[0218] S505. The electronic device 100 determines whether the communication connection 2 is disconnected.

[0219] When the communication connection 2 is not disconnected, the electronic device 100 can receive a response message for the detection heartbeat message returned by the server 300. In some embodiments, the response message may also carry a sending sequence number. The sending sequence number can be used to indicate the sending order of the detection heartbeat message corresponding to the response message. The electronic device 100 can determine whether the communication connection 2 is not disconnected based on whether the response message corresponding to the detection heartbeat message is received.

[0220] If the communication connection 2 is disconnected, it indicates that the current heartbeat cycle may be greater than the timeout period.

[0221] If the communication connection 2 is not disconnected, it indicates that the current heartbeat cycle is less than or equal to the timeout period.

[0222] When the electronic device 100 determines that the communication connection 2 is disconnected, the electronic device 100 may execute the following step S506.

[0223] When the electronic device 100 determines that the communication connection 2 is not disconnected, the electronic device 100 may execute the following step S507.

[0224] S506 . The electronic device 100 updates the detection upper limit of the detection interval and re-establishes the communication connection 2 with the server 300 .

[0225] If the communication connection 2 is disconnected, it indicates that the current heartbeat cycle is greater than the timeout period of the electronic device 200. At this time, the current heartbeat cycle can be determined as the detection upper limit of the detection interval.

[0226] After executing step S506, the electronic device 100 may execute the following step S508.

[0227] S507. The electronic device 100 updates the detection lower limit of the detection interval.

[0228] If the communication connection 2 is not disconnected, it indicates that the current heartbeat cycle is less than or equal to the timeout period of the electronic device 200. At this time, the current heartbeat cycle can be determined as the detection lower limit of the detection interval.

[0229] According to the relevant content of the timeout period, if the heartbeat period of a communication connection is equal to the timeout period, the heartbeat message sent on the communication connection each time may be sent successfully or fail to be sent. In order to avoid the communication connection being disconnected, the heartbeat period of the communication connection should be less than the timeout period. It should be noted that when the communication connection 2 is not disconnected, the current heartbeat period may be equal to the timeout period.

[0230] In some embodiments, in order to avoid the situation where the heartbeat cycle 2 is equal to the timeout period, the electronic device 100 can also subtract a constant (e.g., 10 seconds, 5 seconds, etc.) from the heartbeat cycle, and update the difference between the heartbeat cycle and the constant as the detection lower limit of the detection interval. In this way, by introducing a fixed error, it is possible to avoid the detected heartbeat cycle 2 being equal to the timeout period, thereby improving the stability of the detection result.

[0231] After executing step S507, the electronic device 100 may execute the following step S508.

[0232] S508. The electronic device 100 determines whether the stop condition is met.

[0233] The stop conditions may include but are not limited to any one or more of the following: the difference between the detection upper limit and the detection lower limit is less than a preset value, the detection time length is greater than a preset time length, the number of updates of the detection interval is greater than a preset number, etc.

[0234] If the electronic device 100 determines that the stop condition is met, the electronic device 100 may execute the following step S509 .

[0235] If the electronic device 100 determines that the stop condition is not met, the electronic device 100 may re-execute the above step S502.

[0236] S509. The electronic device 100 determines the heartbeat cycle 2 based on the detection interval.

[0237] In some embodiments, the electronic device 100 may determine the detection lower limit of the current detection interval as heartbeat cycle 2.

[0238] Understandably, Figure 5 The embodiment shown is only an example. In other embodiments, the electronic device 100 may also adopt Figure 5 The illustrated embodiments determine the heartbeat cycle 2 in different ways, which is not limited in the present application.

[0239] It should be noted that if multiple detection connections are established between the electronic device 100 and the server 300, the electronic device 100 can use different heartbeat cycle update methods on different detection connections, and determine the heartbeat cycle 2 based on the detection results of the multiple detection connections. The specific method can refer to the following Figure 6 The relevant contents in the illustrated embodiment will not be described in detail here.

[0240] S404. The electronic device 100 disconnects the communication connection 2 with the server 300.

[0241] It should be noted that after executing step S403, the electronic device 100 may execute step S404 and step S405 simultaneously, or may execute step S404 first and then step S405, or may execute step S405 first and then step S404. This application does not limit the execution order of step S404 and step S405.

[0242] After determining the heartbeat cycle 2 , the electronic device 100 may disconnect the communication connection 2 .

[0243] In some embodiments, if the detection connection includes multiple communication connections, after determining the heartbeat cycle 2, the electronic device 100 can disconnect all the detection connections.

[0244] S405. The electronic device 100 sends a service heartbeat message to the server 300 through the communication connection 1 based on the heartbeat cycle 2.

[0245] After determining the heartbeat cycle 2 , the electronic device 100 may reset the heartbeat cycle of the communication connection 1 , and set the heartbeat cycle of the communication connection 1 to the heartbeat cycle 2 .

[0246] In this way, the electronic device 100 can maintain the communication connection 1 based on the heartbeat cycle 2, reducing the power consumption caused by the sending of the heartbeat message. Moreover, during the detection of the heartbeat cycle 2, the communication connection 1 is always connected, and the service data is transmitted on the communication connection 1, which can avoid the interruption of the service data during the detection process.

[0247] In a possible implementation, after establishing the communication connection 1, the electronic device 100 can continuously update the heartbeat cycle of the communication connection 1 based on the detection result during the detection of the heartbeat cycle 2, and send a service heartbeat message based on the updated heartbeat cycle.

[0248] For example, Figure 6 A schematic diagram of a process of sending a service heartbeat message by the electronic device 100 on the communication connection 1 during the process of detecting the heartbeat cycle 2 provided in an embodiment of the present application is shown.

[0249] like Figure 6 As shown, in the process of detecting heartbeat cycle 2, the process of sending the service heartbeat message of the electronic device 100 on the communication connection 1 may include the following steps:

[0250] S601. The electronic device 100 updates the maximum heartbeat period Tmax based on the detection result on the communication connection 2.

[0251] The electronic device 100 can detect one or more available heartbeat cycles in the process of detecting the heartbeat cycle 2 based on the communication connection 2. An available heartbeat cycle refers to a heartbeat cycle that can maintain the communication connection between the electronic device 100 and the server 300, that is, the heartbeat cycle is less than the timeout period.

[0252] In some embodiments, the electronic device 100 may store a maximum heartbeat cycle Tmax, where the maximum heartbeat cycle Tmax refers to a heartbeat cycle with the largest value among all available heartbeat cycles detected.

[0253] In some embodiments, the electronic device 100 may store a heartbeat cycle table, which may include a maximum heartbeat cycle Tmax. The maximum heartbeat cycle Tmax may be the currently detected maximum available heartbeat cycle.

[0254] Illustratively, Table 2 shows a heartbeat cycle table stored in an electronic device 100 provided in an embodiment of the present application.

[0255] Table 2

[0256] Maximum heart rate Tmax=T1 Detection upper limit T2 Detection limit T1

[0257] As shown in Table 2, the heartbeat cycle table stored in the electronic device 100 may include a maximum heartbeat cycle, and optionally, may also include an upper detection limit and a lower detection limit, which may be the above Figure 5 The two ends of the detection interval in the embodiment shown. According to Table 2, the maximum heartbeat period Tmax can be T1, the upper detection limit can be T2, and the lower detection limit can be T1.

[0258] It can be understood that the embodiment shown in Table 2 is only an example. In the embodiments of the present application, the heartbeat cycle table may also include more, less or different content than the above embodiments, and the present application does not limit it here.

[0259] In one possible implementation, when the electronic device 100 detects a new available heartbeat cycle and the value of the available heartbeat cycle is greater than the currently stored maximum heartbeat cycle Tmax, the electronic device 100 can update the value of the maximum heartbeat cycle Tmax, that is, determine the value of Tmax to be the new available heartbeat cycle.

[0260] Exemplarily, if the electronic device 100 determines through the communication connection 2 that the heartbeat cycle T3 is an available heartbeat cycle, and T3 is greater than T1, the electronic device 100 can update the heartbeat cycle table shown in Table 2 above to the heartbeat cycle table shown in Table 3 below.

[0261] Table 3

[0262] Maximum heart rate Tmax=T3 Detection upper limit T2 Detection limit T3

[0263] As shown in Table 3, the heartbeat period table stored in the electronic device 100 may include a maximum heartbeat period, and optionally, may also include an upper detection limit and a lower detection limit. According to Table 3, the maximum heartbeat period Tmax may be T3, the upper detection limit may be T2, and the lower detection limit may be T3. That is, the values ​​of the maximum heartbeat period and the lower detection limit in the heartbeat period table may be updated to T3.

[0264] It can be understood that the embodiment shown in Table 3 is only an example. In the embodiments of the present application, the heartbeat cycle table may also include more, less or different content than the above embodiments, and the present application does not limit it here.

[0265] S602 . The electronic device 100 determines the next heartbeat time of the communication connection 1 based on the heartbeat cycle of the communication connection 1 .

[0266] exist Figure 6 In the illustrated embodiment, the next heartbeat time refers to the time when the electronic device 100 sends a service heartbeat message via the communication connection 1 next time.

[0267] The electronic device 100 can determine the next heartbeat time based on the heartbeat cycle of the communication connection 1 and the last heartbeat time. It should be noted that if the next heartbeat is the first heartbeat, the electronic device 100 can determine the next heartbeat time based on the heartbeat cycle of the communication connection 1 and the establishment time of the communication connection 1.

[0268] After executing step S602, the electronic device 100 may execute the following step S603.

[0269] S603. When the next heartbeat time arrives, the electronic device 100 determines whether the maximum heartbeat period Tmax is greater than the heartbeat period of the communication connection 1.

[0270] If the maximum heartbeat period Tmax is greater than the heartbeat period of the communication connection 1 , the electronic device 100 may execute the following step S604 to update the heartbeat period of the communication connection 1 .

[0271] If the maximum heartbeat period Tmax is less than or equal to the heartbeat period of the communication connection 1, the electronic device 100 may execute the following step S605.

[0272] S604. The electronic device 100 determines that the heartbeat period of the communication connection 1 is the maximum heartbeat period Tmax.

[0273] After executing step S604, the electronic device 100 may execute the above step S602.

[0274] S605. The electronic device 100 sends a service heartbeat message to the server 300 via the communication connection 1.

[0275] After executing step S605, the electronic device 100 may execute the above step S602.

[0276] Understandably, Figure 6 The shown embodiment is only an exemplary description. During the process of detecting heartbeat cycle 2, the electronic device 100 can update the heartbeat cycle of the business connection based on the detection results on the detection connection. In an embodiment of the present application, the detection connection can also include more communication connections than the above embodiment, and the method of updating the heartbeat cycle on the business connection can also be different from the above embodiment. The present application does not limit this.

[0277] In this way, during the process of detecting heartbeat cycle 2, the electronic device 100 can update the heartbeat cycle of the communication connection 1 based on the detection result on the communication connection 2, thereby reducing power consumption and improving the battery life of the electronic device 100.

[0278] In another possible implementation, the electronic device 100 may also synchronously update the heartbeat period of the communication connection 1 after updating the maximum heartbeat period Tmax based on the detection result on the communication connection 2, and send a service heartbeat message on the communication connection 1 based on the updated heartbeat period. This application is not limited here.

[0279] In one possible implementation, when the electronic device 100 detects heartbeat cycle 2 based on communication connection 2, if the difference between the next sending time of the service heartbeat message on communication connection 1 and the next sending time of the detection heartbeat message on communication connection 2 is within a preset time interval (for example, less than or equal to 5 seconds, less than or equal to 10 seconds, etc.), then the electronic device 100 can control communication connection 1 and communication connection 2 to send the service heartbeat message and the detection heartbeat message at the same time.

[0280] In this way, if the electronic device 100 is in a low power consumption state (or screen-off state), the electronic device 100 only needs to be woken up once to complete the sending of service heartbeat messages and detection heartbeat messages, thereby reducing the number of times the electronic device 100 is woken up, reducing the power consumption of the electronic device 100, and thus improving the battery life of the electronic device 100.

[0281] A communication method provided in an embodiment of the present application is introduced below with reference to specific examples.

[0282] like Figure 7As shown, the moment when the electronic device 100 sends multiple service heartbeat messages on the communication connection 1 can be displayed in the one-dimensional coordinate system OX1, and the moment when the electronic device 100 sends multiple detection heartbeat messages on the communication connection 2 can be displayed in the one-dimensional coordinate system OX2. The one-dimensional coordinate system OX1 can include a horizontal axis X1, and the horizontal axis X1 can represent time; the one-dimensional coordinate system OX2 can include a horizontal axis X2, and the horizontal axis X2 can represent time, and the moments on the horizontal axis X1 and the horizontal axis X2 correspond one to one.

[0283] On the horizontal axis X1, a triangle may represent the sending of a service heartbeat message. On the horizontal axis X2, a circle may represent the establishment of a communication connection 2, a hollow triangle may represent the sending of a detection heartbeat message, and a solid triangle may represent the failure of the sending of the detection heartbeat message.

[0284] according to Figure 7 It can be known that the interaction between the electronic device 100 and the server 300 on the communication connection 1 and the communication connection 2 may include the following steps:

[0285] 1. At time t0, the electronic device 100 has established a communication connection 1 with the server 300.

[0286] 2. From time t0 to time t1, the electronic device 100 sends a service heartbeat message to the server 300 on the communication connection 1 based on the heartbeat period T.

[0287] The time interval between time t0 and time t1 may be 2T.

[0288] 3. At time t1, the electronic device 100 detects that the detection conditions are met and establishes a communication connection 2 with the server 300.

[0289] Communication connection 2 is a detection connection, and no service data will be transmitted on communication connection 2.

[0290] 4. From time t1 to time t2, the electronic device 100 sends a detection heartbeat message to the server 300 on the communication connection 2 based on the heartbeat cycle 2T.

[0291] The heartbeat period 2T of the communication connection 2 may be determined based on the heartbeat period T of the communication connection 1. The time interval between the time t1 and the time t2 is 2T.

[0292] 5. At time t2, the electronic device 100 sends a service heartbeat message to the server 300 on communication connection 1, and at the same time, sends a detection heartbeat message to the server 300 on communication connection 2.

[0293] 6. After determining that the detection heartbeat message at time t2 is sent successfully, the electronic device 100 can synchronize the heartbeat period 2T to the communication connection 1.

[0294] 7. The electronic device 100 can determine a new heartbeat period (2T-x) on the communication connection 1 based on the heartbeat period 2T synchronized with the communication connection 2, where x can be a preset constant.

[0295] 8. From time t2 to time t3, the electronic device 100 sends a service heartbeat message to the server 300 on the communication connection 1 based on the heartbeat cycle (2T-x).

[0296] 9. From time t2 to time t3, the electronic device 100 sends a service heartbeat message to the server 300 on the communication connection 2 based on the heartbeat cycle (4T-2x).

[0297] The heartbeat cycle (4T-2x) may be determined based on the heartbeat cycle 2T. The time interval between time t2 and time t3 may be (4T-2x).

[0298] In some embodiments, the electronic device 100 can also determine the heartbeat cycle 4T based on the last heartbeat cycle 2T of the communication connection 2. Since time t3 is the time when the service heartbeat message on the communication connection 1 is sent, and the difference between time t3 and the time when the next detection heartbeat message of the communication connection 2 is sent belongs to a preset time interval (for example, less than 60 seconds, less than 30 seconds), etc., the electronic device 100 can adjust the time when the next detection heartbeat message of the communication connection 2 is sent to time t3.

[0299] 10. At time t3, the electronic device 100 sends a service heartbeat message to the server 300 on communication connection 1, and at the same time, sends a detection heartbeat message to the server 300 on communication connection 2.

[0300] 11. At time t31, after determining that the detection heartbeat message at time t3 has failed to be sent, the electronic device 100 can re-establish the communication connection 2 with the server 300 and change the heartbeat period of the communication connection 2 to the heartbeat period (3T-x).

[0301] The time t31 is later than the time t3. The heartbeat cycle (3T-x) can be determined based on the heartbeat cycle 2T and the heartbeat cycle (4T-x).

[0302] 12. From time t3 to time t4, the electronic device 100 can continue to send service heartbeat messages to the server 300 on the communication connection 1 based on the heartbeat cycle (2T-x).

[0303] 13. At time t4, the electronic device 100 sends a detection heartbeat message to the server 300 on the communication connection 2.

[0304] The time interval between t31 and t4 is (3T-x).

[0305] 14. After determining that the detection heartbeat message at time t2 is sent successfully, the electronic device 100 can synchronize the heartbeat cycle (3T-x) to the communication connection 1.

[0306] 15. The electronic device 100 can determine a new heartbeat cycle (3T-2x) on the communication connection 1 based on the heartbeat cycle (3T-x) synchronized with the communication connection 2.

[0307] 16. The electronic device 100 detects that the stop condition is met and disconnects the communication connection 2.

[0308] 17. After time t4, the electronic device 100 can send a service heartbeat message to the server 300 on the communication connection 1 based on the heartbeat cycle (3T-2x).

[0309] In this way, the electronic device 100 can maintain the communication connection 1 for transmitting business data during the detection of the heartbeat cycle 2, and determine the heartbeat cycle 2 through the detection connection such as the communication connection 2, which can avoid the interruption of business data and reduce the power consumption of the electronic device 100.

[0310] Figure 8 A schematic diagram of the execution flow of the business server 310 and the detection server 320 in the server 300 during the detection heartbeat cycle 2 provided in an embodiment of the present application is shown.

[0311] like Figure 8 As shown, during the detection of heartbeat cycle 2, the specific process executed by the server 300 may include the following steps:

[0312] S801 , the service server 310 establishes a communication connection 1 with the electronic device 100 .

[0313] In some embodiments, the specific method for the business server 310 to establish a communication connection 1 with the electronic device 100 and the detection server 320 to establish a communication connection 2 with the electronic device 100 can refer to the method for establishing a TCP long link, which will not be described in detail in this application.

[0314] S802 . The service server 310 receives the service heartbeat message sent by the electronic device 100 through the communication connection 1 .

[0315] Step S802 is a step that can be executed repeatedly.

[0316] As can be seen from the above embodiment, the electronic device 100 can send a service heartbeat message to the service server 310 based on the heartbeat cycle of the communication connection 1 (e.g., heartbeat cycle 1) on the communication connection 1. Therefore, the service server 310 can receive the service heartbeat message periodically sent by the electronic device 100 on the communication connection 1.

[0317] In some embodiments, the service server 310 may respond to the service heartbeat message by sending a response message to the electronic device 100 through the communication connection 1, wherein the response message is used to notify the electronic device 100 that the service heartbeat message is sent successfully.

[0318] In other embodiments, the business server 310 may also receive a business data acquisition request sent by the electronic device 100 through the communication connection 1, where the business data acquisition request is used to request the business server 300 to send business data to the electronic device 100. In response to the business data acquisition request, the business server 310 may send business data to the electronic device 100 through the communication connection 1.

[0319] S803. The detection server 320 establishes a communication connection 2 with the electronic device 100, and obtains the heartbeat time information sent by the electronic device 100. The heartbeat time information is used to determine the time when the detection server 320 receives the detection heartbeat message next time.

[0320] In some embodiments, the heartbeat time information may include the next heartbeat cycle and / or the next heartbeat time. Optionally, the heartbeat time information may also include the current heartbeat time.

[0321] In some embodiments, the next heartbeat cycle and / or the next heartbeat time can be determined based on the current heartbeat cycle and a preset heartbeat cycle algorithm. For example, the next heartbeat cycle can be the sum of the current heartbeat cycle and the step length, or the next heartbeat cycle can be the product of the current heartbeat cycle and a constant, or the next heartbeat cycle can be the average of the current heartbeat cycle and the detection upper limit, etc. The specific calculation method can refer to the above Figure 5 The related descriptions in step S502 and step S503 are not repeated here.

[0322] S804. The detection server 320 determines the receiving time based on the newly received heartbeat time information.

[0323] The receiving time refers to the time at which the detection server 320 receives the detection heartbeat message via the communication connection 2 next time.

[0324] In some embodiments, the heartbeat time information may include the next heartbeat cycle. In this case, the detection server 320 may determine the receiving time based on the next heartbeat cycle. Exemplarily, the next heartbeat cycle and the receiving time satisfy the relationship shown in the following formula (5) and formula (6).

[0325] Receiving time = next heartbeat time + transmission time Formula (5)

[0326] Next heartbeat time = next heartbeat cycle + current heartbeat time formula (6)

[0327] According to the above formula (5) and formula (6), the receiving time can be the sum of the next heartbeat time and the transmission time, wherein the transmission time can be a preset constant, such as 20 seconds, 10 seconds, etc. The next heartbeat time can be the sum of the current heartbeat time and the next heartbeat cycle. In some embodiments, the heartbeat time information can include the current heartbeat time. In other embodiments, the current heartbeat time can also be determined based on the heartbeat time information carried in the previous detection heartbeat message.

[0328] As another example, the next heartbeat cycle and the receiving time satisfy the relationship shown in the following formula (7).

[0329] Receiving time = last receiving time + next heartbeat cycle formula (7)

[0330] According to the above formula (5) and formula (6), the receiving time can also be the sum of the last receiving time and the next heartbeat cycle. Among them, the current receiving time refers to the time when the heartbeat time information is received closest to the current time.

[0331] In some other embodiments, the heartbeat time information may include the next heartbeat time. In this case, the detection server 320 may determine the receiving time based on the next heartbeat time by using the above formula (5).

[0332] It is understandable that the embodiments here are just some examples. In the embodiments of the present application, the detection server 320 can also calculate the receiving time based on the heartbeat time information in a different way from the above embodiments, and the present application does not limit this.

[0333] S805. When the receiving time arrives, the detection server 320 determines whether the detection heartbeat message is received.

[0334] When the receiving time arrives, the detection server 320 can determine whether the detection heartbeat message sent by the electronic device 100 through the communication connection 2 is received within the preset time period. The preset time period can be the time period from receiving the heartbeat time information used to calculate the receiving time to the arrival of the receiving time.

[0335] If the detection server 320 receives the detection heartbeat message, it indicates that the communication connection 2 can be maintained normally. At this time, the detection server 320 can execute the following step S806.

[0336] If the detection server 320 does not receive the detection heartbeat message, it indicates that the communication connection 2 may not be maintained, and the detection server 320 may execute the following step S807.

[0337] S806. The detection server 320 determines new heartbeat time information based on the newly received detection heartbeat message.

[0338] The detection heartbeat message may carry heartbeat time information. The specific content of the heartbeat time information may refer to the relevant description in the above step S803.

[0339] It should be noted that the heartbeat time information received each time is used to determine the time at which the detection server 320 receives the next detection heartbeat message, that is, the heartbeat time information received each time is different.

[0340] After executing step S806, the detection server 320 may execute the above step S804.

[0341] S807. The detection server 320 disconnects the communication connection 2.

[0342] After disconnecting the communication connection 2, the detection server 320 may re-execute the above step S803.

[0343] In this way, the detection server 320 can determine whether to disconnect the communication connection 2 based on the heartbeat time information carried in the detection heartbeat message. The power consumption of the detection server 320 is reduced.

[0344] Understandably, Figure 8 The embodiment shown is only an example. In some embodiments, during the process of detecting heartbeat cycle 2, the server 300 may also perform more, fewer or different steps than the above embodiment, and the present application does not limit this. In addition, if the detection server 320 is not set in the server 300, the service server 310 in the server 300 may also perform the above Figure 8 The relevant steps performed by the detection server 320 in the illustrated embodiment are not limited in this application.

[0345] In some embodiments, when the detection condition is met, the electronic device 100 can establish multiple detection connections (such as communication connection 2 and communication connection 3, etc.) with the server 300 through the electronic device 200. In this case, the electronic device 100 can use different heartbeat cycle calculation methods on different detection connections, and update the detection upper limit and detection lower limit of the detection interval based on the detection results on multiple detection connections, thereby determining the heartbeat cycle 2.

[0346] In this way, the electronic device 100 can determine the heartbeat cycle 2 through multiple detection connections, thereby improving the detection speed of the heartbeat cycle 2.

[0347] The following introduces the functional modules of a communication system 10 provided in an embodiment of the present application.

[0348] Fig. 9 A schematic diagram of functional modules of a communication system 10 provided in an embodiment of the present application.

[0349] like Fig. 9 As shown, the communication system 10 may include an electronic device 100, an electronic device 200 and a server 300. The electronic device 100 may include a communication module 911, a service module 912, and a heartbeat control module 913. The electronic device 200 may include an intranet communication module 921, a network address translation module 922 and a public network communication module 923. The server 300 may include a service service module 931 and a detection service module 932.

[0350] In the electronic device 100, the communication module 911 can establish a communication connection with other devices, for example, establish a communication connection 1 with the server 300 through the electronic device 200, and can also establish a communication connection 2 with the server 300 through the electronic device 200, etc. The communication module 911 can communicate with other devices. In some embodiments, the communication module 911 can send a business heartbeat message on the communication connection 1, send a detection heartbeat message on the communication connection 2, etc. In some embodiments, the communication module 911 can also receive business data through the communication connection 1, and send the received business data to the business module 912. In other embodiments, the communication module 911 can also receive a business data acquisition request sent by the business module 912, and send the business data acquisition request to the server 300 through the communication connection 1.

[0351] The service module 912 may send a service data acquisition request to the communication module 911, and the service data acquisition request is used to request the server 300 to send service data through the communication connection 1. The service module 912 may also receive the service data sent by the communication module 911, and execute corresponding services based on the service data.

[0352] The heartbeat control module 913 can control the sending of heartbeat messages on multiple communication connections. In some embodiments, the heartbeat control module 913 can set the sending time of each heartbeat message on communication connection 1, and can also set the sending time of each heartbeat message on communication connection 2. When the sending time of the business heartbeat message arrives, the heartbeat control module 913 can control the communication module 911 to send the business heartbeat message through communication connection 1. When the sending time of the detection heartbeat message arrives, the heartbeat control module 913 can control the communication module 911 to send the detection heartbeat message through communication connection 2. In some embodiments, the heartbeat control module 913 can also align the sending time of one or more business heartbeat messages and detection heartbeat messages. The specific alignment method can refer to the relevant content in the above embodiment, which will not be repeated here.

[0353] In the electronic device 200, the intranet communication module 921 can establish a communication connection (e.g., communication connection A1 and communication connection A2) with the electronic device 100. The network address translation module 922 can translate the intranet IP address of the electronic device 100 to obtain a corresponding public network IP address. The public network communication module 923 can establish a communication connection (e.g., communication connection B1 and communication connection B2) with the server 300 based on the translated public network IP address.

[0354] In the server 300, the business service module 931 can establish a communication connection 1 with the electronic device 100 through the electronic device 200, and the communication connection 1 can be used to transmit business data and can also be used to transmit a business data acquisition request. The business service module 931 can receive a business data acquisition request sent by the electronic device 100 through the communication connection 1, and in response to the business data acquisition request, send business data to the electronic device 100 through the communication connection 1.

[0355] The detection service module 932 can establish a communication connection 2 with the electronic device 100 through the electronic device 200, and the communication connection 2 can be used to detect the heartbeat cycle 2. In some embodiments, the detection service module 932 can also establish multiple communication connections with the electronic device 100 through the electronic device 200, and determine the heartbeat cycle 2 based on the multiple communication connections, which is not limited in this application. The detection service module 932 can receive a detection heartbeat message sent by the electronic device 100 through the communication connection 2. In some embodiments, the detection service module 932 can also send a response message to the electronic device 100 in response to the detection heartbeat message. The response message is used to notify the electronic device 100 that the server 300 has received the detection heartbeat message.

[0356] Understandably, Fig. 9 The embodiment shown is only an example. In the embodiment of the present application, the communication system 10 may also include more, less or different devices than the above embodiment, and each electronic device (or server) may also include more, less or different functional modules than the above embodiment, which is not limited in the present application. In addition, in some embodiments, multiple functional modules in the above embodiment may also be integrated into one functional module, or a functional module in the above embodiment may also be divided into multiple different functional modules, which is not limited in the present application.

[0357] Fig.10 A flow chart of a communication method provided in an embodiment of the present application is shown.

[0358] like Fig.10 As shown, the specific process of the communication method may include the following steps:

[0359] S1001. A first electronic device establishes a first connection with a server.

[0360] The first electronic device may be the electronic device 100 in the above embodiment, and the server may be the server 300 in the above embodiment. The first connection may be the communication connection 1 in the above embodiment, and the first connection is a service connection.

[0361] In a possible implementation, the server is a server set, and the server includes a first server and a second server; the first server is used to establish a first connection with the first electronic device, and the second server is used to establish a second connection with the first electronic device.

[0362] The first server may be the service server in the above embodiment, the second server may be the detection server in the above embodiment, and the second connection may be the communication connection 2 in the above embodiment, and the second connection is a detection connection.

[0363] In this way, different servers in the server set can provide business services and detection services respectively, which can better control data transmission on different connections.

[0364] S1002. The first electronic device sends a heartbeat message of the first type to the server through the first connection based on the first period.

[0365] The first cycle may be the heartbeat cycle 1 in the above embodiment.

[0366] The first type of heartbeat message may be the service heartbeat message in the above embodiment.

[0367] S1003. The first electronic device establishes a second connection with the server, where the second connection is used to transmit a second type of heartbeat message.

[0368] The second connection may be the communication connection 2 in the above embodiment. The second type of heartbeat message may be the detection heartbeat message in the above embodiment.

[0369] In one possible implementation, the first electronic device establishes a second connection with the server, specifically including: when it is detected that a detection condition is met, the first electronic device establishes a second connection with the server; wherein the detection condition includes any one or more of the following: the first electronic device establishes a communication connection with the server for the first time, the time from the last detection reaches a first time length, a first operation of the user is received, the first operation is used to instruct the first electronic device to determine the second period, and a detection instruction is received, the detection instruction is used to instruct the first electronic device to determine the second period.

[0370] For other detailed descriptions of the detection conditions, please refer to the above Figure 4 The relevant description in the illustrated embodiment will not be repeated here.

[0371] In this way, when the detection condition is met, a detection connection (ie, the second connection) can be established, and the second period can be determined based on the detection connection.

[0372] In a possible implementation, the format of the heartbeat message of the first category is the same as the format of the heartbeat message of the second category; or, the format of the heartbeat message of the first category is different from the format of the heartbeat message of the second category.

[0373] In a possible implementation, the content of the first type of heartbeat message is more than that of the second type of heartbeat message. In this way, the power consumption of sending the second type of heartbeat message can be saved.

[0374] In some embodiments, the format of the first type of heartbeat message and the format of the second type of heartbeat message may also refer to the relevant content in the embodiment shown in Table 1 above.

[0375] S1004. The first electronic device determines a second period based on the second connection.

[0376] The second cycle may be the heartbeat cycle 2 in the above embodiment.

[0377] In a possible implementation, the second period is greater than the first period.

[0378] In this way, the frequency of sending heartbeat messages on the service connection can be reduced, power consumption can be reduced, and battery life can be improved.

[0379] In a possible implementation, the specific content of step S1004 can also refer to the above Figure 5 The relevant description in the illustrated embodiment will not be repeated here.

[0380] S1005. The first electronic device sends a heartbeat message of the first type to the server through the first connection based on the second period.

[0381] It should be noted that step S1005 and step S1006 may be steps executed simultaneously, or step S1005 may be executed first and then step S1006, or step S1006 may be executed first and then step S1005. This application does not limit the execution order of step S1005 and step S1006.

[0382] S1006. The first electronic device disconnects the second connection.

[0383] In this way, service data can be transmitted on the first connection (ie, service connection), and the heartbeat cycle can be detected on the second connection (ie, detection connection), thereby avoiding interruption of service data transmission during the detection process.

[0384] In one possible implementation, the moment when the first electronic device establishes a second connection with the server is the first moment; the second period is determined based on the second connection, specifically including: at the second moment, sending a first message to the server through the second connection, the first message is a heartbeat message of the second type, and the second moment is later than the first moment; receiving a first response, the first response is a response sent by the server through the second connection in response to the first message; when it is detected that the stop condition is met, determining the second period based on the time interval between the first moment and the second moment.

[0385] In a possible implementation manner, the second period is the time interval between the first moment and the second moment, or the second period is the difference between the time interval between the first moment and the second moment and a fourth constant.

[0386] For example, refer to the above Figure 7 In the embodiment shown, the first time may be time t31, the second time may be time t4. The second period may be the time interval between time t31 and time t4, or the difference between the time interval between time t31 and time t4 and a preset fourth constant (eg, x).

[0387] In this way, when it is detected that the stop condition is met, the second period can be determined based on the heartbeat period corresponding to the last successful sending of the heartbeat message on the second connection.

[0388] In one possible implementation, the time interval between the first moment and the second moment is: the product of the first period and a first constant, where the first constant is a positive number greater than 1; or, the sum of the first period and a second constant, where the second constant is a positive number; or, the average value of the first period and a third constant, where the third constant is greater than the first period.

[0389] Exemplarily, the first constant may be the constant a in the above formula (3), the second constant may be the step size in the above formula (2), and the third constant may be the detection upper limit in the above formula (1).

[0390] In this way, the next heartbeat cycle on the second connection can be determined based on the first cycle.

[0391] In one possible implementation, the method further includes: before the first moment, sending a second message to the server via a second connection, the second message being a heartbeat message of the second type; detecting that the second connection is disconnected; and at the first moment, the first electronic device re-establishing a second connection with the server.

[0392] For example, refer to the above Figure 7 In the illustrated embodiment, the first time may be time t31, and the second message may be a detection heartbeat message sent at time t2.

[0393] In this way, after the second connection is disconnected, the second connection can be reestablished, and the second period is determined based on the reestablished second connection.

[0394] In one possible implementation, determining the second period based on the second connection specifically includes: at a third moment, sending a third message to the server through the second connection, the third message being a heartbeat message of the second type; receiving a third response, the third response being a response of the server in response to the third message sent through the second connection; at a fourth moment, sending a fourth message to the server through the second connection, the fourth message being a heartbeat message of the second type, the fourth moment being later than the third moment; receiving a fourth response, the fourth response being a response of the server in response to the fourth message sent through the second connection; and when it is detected that the stop condition is met, determining the second period based on the time interval between the third moment and the fourth moment.

[0395] In a possible implementation manner, the second period is the time interval between the third moment and the fourth moment, or the difference between the time interval between the third moment and the fourth moment and a fourth constant.

[0396] In this way, when it is detected that the stop condition is met, the second period can be determined based on the heartbeat period corresponding to the last successful sending of the heartbeat message on the second connection.

[0397] In one possible implementation, the moment when the first electronic device establishes a second connection with the server is the first moment, the time interval between the first moment and the third moment is the first time interval, and the time interval between the third moment and the fourth moment is the second time interval; the first time interval is less than the second time interval; the method also includes: before the first moment, sending a second message to the server through the second connection, the first message being a heartbeat message of the second type; detecting that the second connection is disconnected; at the first moment, the first electronic device re-establishes the second connection with the server.

[0398] In this way, after the second connection is disconnected, the second connection can be reestablished, and the second period is determined based on the reestablished second connection.

[0399] In one possible implementation, the second time interval is: the product of the first time interval and a first constant, where the first constant is a positive number greater than 1; or, the sum of the first time interval and a second constant, where the second constant is a positive number; or, the average of the first time interval and a third constant, where the third constant is greater than the first time interval.

[0400] In this way, the next heartbeat cycle of the second connection can be determined based on the current heartbeat cycle of the second connection.

[0401] In one possible implementation, before determining the second period based on the second connection, the method also includes: after receiving the third response, sending a first type of heartbeat message to the server through the first connection based on a third period, where the third period is the time interval between the first moment and the third moment.

[0402] In this way, in the process of determining the second period, the heartbeat period of the first connection can be updated in real time based on the detection result on the second connection.

[0403] In one possible implementation, before determining the second period based on the second connection, the method also includes: after receiving the third response, sending a first type of heartbeat message to the server through the first connection based on the third period, and the third period is the difference between the time interval between the first moment and the third moment and a fourth constant.

[0404] Thus, in the process of determining the second period, the heartbeat period of the first connection can be updated in real time based on the detection result on the second connection. Moreover, the heartbeat period of the first connection can be prevented from being equal to the timeout period by introducing a fixed error (ie, the fourth constant).

[0405] In one possible implementation, before the third moment, the method also includes: at the fifth moment, sending a fifth message to the server through the second connection, the fifth message being a heartbeat message of the second type; receiving a fifth response, the fifth response being a response of the server in response to the fifth message sent through the second connection; wherein the time interval between the fifth moment and the third moment is the third time interval, the time interval between the third moment and the fourth moment is the second time interval, and the third time interval is less than the second time interval.

[0406] In this way, when it is detected that the stop condition is met, the second period can be determined based on the heartbeat period corresponding to the last successful sending of the heartbeat message on the second connection.

[0407] In one possible implementation, the second time interval is: the product of the third time interval and a first constant, where the first constant is a positive number greater than 1; or, the sum of the third time interval and a second constant, where the second constant is a positive number; or, the average of the third time interval and the third constant, where the third constant is greater than the third time interval.

[0408] In this way, the next heartbeat cycle of the second connection can be determined based on the current heartbeat cycle of the second connection.

[0409] In one possible implementation, before determining the second period based on the second connection, the method also includes: after receiving the third response, sending a first type of heartbeat message to the server based on a fourth period through the first connection; the fourth period is the time interval between the fifth moment and the third moment, or the fourth period is the difference between the time interval between the fifth moment and the third moment and a fourth constant.

[0410] Thus, in the process of determining the second cycle, the heartbeat cycle of the first connection can be updated in real time based on the detection result on the second connection. In addition, the heartbeat cycle of the first connection can be prevented from being equal to the timeout period by introducing a fixed error (ie, the fourth constant).

[0411] In one possible implementation, the moment when the first electronic device establishes a second connection with the server is the first moment; the second period is determined based on the second connection, specifically including: at a sixth moment, sending a sixth message to the server through the second connection, the sixth message is a heartbeat message of the second type, and the sixth moment is later than the first moment; receiving a sixth response, the sixth response is a response of the server in response to the sixth message sent through the second connection; at a seventh moment, sending a seventh message to the server through the second connection, the seventh message is a heartbeat message of the second type, and the seventh moment is later than the sixth moment; detecting that the second connection is disconnected; when it is detected that the stop condition is met, determining the second period based on the time interval between the first moment and the sixth moment.

[0412] In a possible implementation manner, the second period is the time interval between the first moment and the sixth moment, or the second period is the difference between the time interval between the first moment and the sixth moment and a fourth constant.

[0413] In this way, when it is detected that the stop condition is met, the second period can be determined based on the heartbeat period corresponding to the last successful sending of the heartbeat message on the second connection.

[0414] In a possible implementation, determining the second period based on the second connection specifically includes: at an eighth moment, sending an eighth message to the server through the second connection, the eighth message being a heartbeat message of the second type; receiving an eighth response, the eighth response being a response of the server in response to the eighth message sent through the second connection; at a ninth moment, sending a ninth message to the server through the second connection, the ninth message being a heartbeat message of the second type, and the ninth moment being later than the eighth moment; receiving a ninth response, the ninth response being a response of the server in response to the ninth message sent through the second connection; at a tenth moment, sending a tenth message to the server through the second connection, the tenth message being a heartbeat message of the second type, and the tenth moment being later than the ninth moment; detecting that the second connection is disconnected; and when detecting that the stop condition is met, determining the second period based on the time interval between the eighth moment and the ninth moment.

[0415] In a possible implementation manner, the second period is the time interval between the eighth moment and the ninth moment, or the second period is the difference between the time interval between the eighth moment and the ninth moment and the fourth constant.

[0416] In this way, when it is detected that the stop condition is met, the second period can be determined based on the heartbeat period corresponding to the last successful sending of the heartbeat message on the second connection.

[0417] In one possible implementation, the stop condition includes but is not limited to any one or more of the following: the detection duration reaches a second duration, the number of second-type heartbeat messages sent through the second connection reaches a first number, and the number of second connection establishments reaches a second number.

[0418] For other related information about stop conditions, please refer to the above Figure 5 The relevant description in the illustrated embodiment will not be repeated here.

[0419] In one possible implementation, after the first electronic device establishes a second connection with the server, the method also includes: at the eleventh moment, sending a first type of heartbeat message to the server through the first connection; at the twelfth moment, sending an eleventh message to the server through the second connection, the eleventh message is a second type of heartbeat message, the twelfth moment is later than the eleventh moment, and the time interval between the eleventh moment and the twelfth moment is a fourth time interval; at the twelfth moment, sending the first type of heartbeat message to the server through the first connection, and the absolute value of the difference between the fourth time interval and the first period is less than the first threshold.

[0420] In this way, the times of sending the heartbeat messages on the first connection and the second connection can be aligned, so as to reduce the number of times of waking up the first electronic device and reduce the power consumption of the first electronic device.

[0421] In one possible implementation, the first electronic device establishes a first connection with the server, specifically including: the first electronic device establishes a first connection with the server through the second electronic device; the first electronic device establishes a second connection with the server, specifically including: the first electronic device establishes a second connection with the server through the second electronic device.

[0422] In this way, the first electronic device can establish a communication connection with the server through the second electronic device.

[0423] In a possible implementation manner, the method further includes: the first electronic device establishing a third connection with the server; and determining the second period based on the second connection, specifically including: determining the second period based on the second connection and the third connection.

[0424] The third connection is used to transmit the second type of heartbeat message.

[0425] In this way, the second period may be determined based on a plurality of detection connections.

[0426] The various implementation modes of the present application can be combined arbitrarily to achieve different technical effects.

[0427] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the present application is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions can be transmitted from a website site, computer, server or data center to another website site, computer, server or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line) or wireless (e.g., infrared, wireless, microwave, etc.) mode. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that includes one or more available media integrated. The available medium can be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state disk (SSD)), etc.

[0428] Those skilled in the art can understand that to implement all or part of the processes in the above-mentioned embodiments, the processes can be completed by computer programs to instruct related hardware, and the programs can be stored in computer-readable storage media. When the programs are executed, they can include the processes of the above-mentioned method embodiments. The aforementioned storage media include: ROM or random access memory RAM, magnetic disk or optical disk and other media that can store program codes.

[0429] In short, the above description is only an embodiment of the technical solution of the present invention, and is not intended to limit the protection scope of the present invention. Any modification, equivalent replacement, improvement, etc. made according to the disclosure of the present invention shall be included in the protection scope of the present invention.

Claims

1. A communication method, characterized in that: Applied to a first electronic device, the method includes: The first electronic device establishes a first connection with the server; Sending a first type of heartbeat message to the server based on a first period through the first connection; The first electronic device establishes a second connection with the server, where the second connection is used to transmit a second type of heartbeat message; determining a second period based on the second connection; Sending the first type of heartbeat message to the server based on the second period through the first connection; The second connection is disconnected.

2. The method according to claim 1, characterized in that The second period is greater than the first period.

3. The method according to any one of claims 1 to 2, characterized in that: The first electronic device establishes a second connection with the server, specifically comprising: When it is detected that the detection conditions are met, the first electronic device establishes the second connection with the server; wherein the detection conditions include any one or more of the following: the first electronic device establishes a communication connection with the server for the first time, the time from the last detection reaches a first duration, a first operation of the user is received, the first operation is used to instruct the first electronic device to determine the second period, and a detection instruction is received, the detection instruction is used to instruct the first electronic device to determine the second period.

4. The method according to any one of claims 1 to 3, characterized in that The format of the heartbeat message of the first category is the same as the format of the heartbeat message of the second category; or the format of the heartbeat message of the first category is different from the format of the heartbeat message of the second category.

5. The method according to any one of claims 1 to 4, characterized in that The time when the first electronic device establishes the second connection with the server is a first time; The determining the second period based on the second connection specifically includes: At a second moment, sending a first message to the server through the second connection, the first message being a heartbeat message of the second type, and the second moment being later than the first moment; receiving a first response, where the first response is a response sent by the server through the second connection in response to the first message; When it is detected that the stop condition is met, the second period is determined based on a time interval between the first time and the second time.

6. The method according to claim 5, characterized in that The time interval between the first moment and the second moment is: The product of the first period and a first constant, wherein the first constant is a positive number greater than 1; or, The sum of the first period and a second constant, wherein the second constant is a positive number; or, The average value of the first period and the third constant, the third constant is greater than the first period.

7. The method according to any one of claims 5-6, characterized in that The method further comprises: Before the first moment, sending a second message to the server through the second connection, where the second message is a heartbeat message of the second type; detecting that the second connection is disconnected; At the first moment, the first electronic device re-establishes the second connection with the server.

8. The method according to any one of claims 1 to 4, characterized in that The determining the second period based on the second connection specifically includes: At a third moment, sending a third message to the server through the second connection, where the third message is a heartbeat message of the second type; receiving a third response, where the third response is a response sent by the server through the second connection in response to the third message; At a fourth moment, sending a fourth message to the server through the second connection, the fourth message being a heartbeat message of the second type, the fourth moment being later than the third moment; receiving a fourth response, where the fourth response is a response sent by the server through the second connection in response to the fourth message; When it is detected that the stop condition is satisfied, the second period is determined based on a time interval between the third time instant and the fourth time instant.

9. The method according to claim 8, characterized in that The time when the first electronic device establishes the second connection with the server is a first time, the time interval between the first time and the third time is a first time interval, and the time interval between the third time and the fourth time is a second time interval; the first time interval is less than the second time interval; and the method further includes: Before the first moment, sending a second message to the server through the second connection, where the first message is a heartbeat message of the second type; detecting that the second connection is disconnected; At the first moment, the first electronic device re-establishes the second connection with the server.

10. The method according to claim 9, characterized in that The second time interval is: The product of the first time interval and a first constant, where the first constant is a positive number greater than 1; or, The sum of the first time interval and a second constant, wherein the second constant is a positive number; or, The average value of the first time interval and the third constant, the third constant is greater than the first time interval.

11. The method according to claim 9 or 10, characterized in that: Before determining a second period based on the second connection, the method further includes: After receiving the third response, the heartbeat message of the first type is sent to the server through the first connection based on a third period, where the third period is the time interval between the first moment and the third moment.

12. The method according to claim 9 or 10, characterized in that: Before determining a second period based on the second connection, the method further includes: After receiving the third response, the heartbeat message of the first type is sent to the server through the first connection based on a third period, where the third period is the difference between the time interval between the first moment and the third moment and a fourth constant.

13. The method according to claim 8, characterized in that Before the third moment, the method further includes: At a fifth moment, sending a fifth message to the server through the second connection, where the fifth message is a heartbeat message of the second type; A fifth response is received, wherein the fifth response is a response sent by the server through the second connection in response to the fifth message; wherein the time interval between the fifth moment and the third moment is the third time interval, the time interval between the third moment and the fourth moment is the second time interval, and the third time interval is less than the second time interval.

14. The method according to claim 13, characterized in that The second time interval is: The product of the third time interval and a first constant, wherein the first constant is a positive number greater than 1; or, The sum of the third time interval and a second constant, wherein the second constant is a positive number; or, The third time interval is an average value of the third time interval and the third constant, and the third constant is greater than the third time interval.

15. The method according to claim 13 or 14, characterized in that Before determining a second period based on the second connection, the method further includes: After receiving the third response, the heartbeat message of the first type is sent to the server through the first connection based on a fourth period; the fourth period is the time interval between the fifth moment and the third moment, or the fourth period is the difference between the time interval between the fifth moment and the third moment and a fourth constant.

16. The method according to any one of claims 1 to 4, characterized in that The time when the first electronic device establishes the second connection with the server is a first time; The determining the second period based on the second connection specifically includes: At a sixth moment, sending a sixth message to the server through the second connection, the sixth message being a heartbeat message of the second type, the sixth moment being later than the first moment; receiving a sixth response, where the sixth response is a response sent by the server through the second connection in response to the sixth message; At a seventh moment, sending a seventh message to the server through the second connection, the seventh message being a heartbeat message of the second type, the seventh moment being later than the sixth moment; detecting that the second connection is disconnected; When it is detected that the stop condition is satisfied, the second period is determined based on a time interval between the first moment and the sixth moment.

17. The method according to any one of claims 1 to 4, characterized in that The determining the second period based on the second connection specifically includes: At an eighth moment, sending an eighth message to the server through the second connection, where the eighth message is a heartbeat message of the second type; receiving an eighth response, where the eighth response is a response sent by the server through the second connection in response to the eighth message; At a ninth moment, sending a ninth message to the server through the second connection, the ninth message being a heartbeat message of the second type, the ninth moment being later than the eighth moment; receiving a ninth response, where the ninth response is a response sent by the server through the second connection in response to the ninth message; At a tenth moment, sending a tenth message to the server through the second connection, the tenth message being a heartbeat message of the second type, the tenth moment being later than the ninth moment; detecting that the second connection is disconnected; When it is detected that the stop condition is satisfied, the second period is determined based on a time interval between the eighth moment and the ninth moment.

18. The method according to claim 17, characterized in that The second period is the time interval between the eighth moment and the ninth moment, or the difference between the time interval between the eighth moment and the ninth moment and a fourth constant.

19. The method according to any one of claims 5 to 18, characterized in that: The stop condition includes any one or more of the following: The detection duration reaches a second duration, the number of times the second type of heartbeat messages are sent through the second connection reaches a first number, and the number of times the second connection is established reaches a second number.

20. The method according to any one of claims 1 to 19, characterized in that After the first electronic device establishes a second connection with the server, the method further includes: At an eleventh moment, sending a heartbeat message of the first type to the server through the first connection; At a twelfth moment, an eleventh message is sent to the server through the second connection, where the eleventh message is a heartbeat message of the second type, the twelfth moment is later than the eleventh moment, and the time interval between the eleventh moment and the twelfth moment is a fourth time interval; At the twelfth moment, the heartbeat message of the first type is sent to the server through the first connection, and the absolute value of the difference between the fourth time interval and the first period is less than a first threshold.

21. The method according to any one of claims 1 to 20, characterized in that The first electronic device establishes a first connection with the server, specifically comprising: The first electronic device establishes the first connection with the server through the second electronic device; The first electronic device establishes a second connection with the server, specifically comprising: The first electronic device establishes the second connection with the server through the second electronic device.

22. The method according to any one of claims 1 to 4, characterized in that The method further comprises: The first electronic device establishes a third connection with the server; The determining the second period based on the second connection specifically includes: The second period is determined based on the second connection and the third connection.

23. A communication system, characterized in that: The communication system includes a first electronic device, a first server and a second server; The first electronic device is configured to establish a first connection with the first server; and send a first type of heartbeat message to the first server based on a first period through the first connection; Establishing a second connection with the second server, the second connection being used to transmit a second type of heartbeat message; determining a second period based on the second connection; sending the first type of heartbeat message to the first server through the first connection based on the second period; disconnecting the second connection; The first server is used to establish the first connection with the first electronic device, where the first connection is used to transmit service data and the heartbeat message of the first category; The second server is used to establish the second connection with the first electronic device, and the second connection is used to transmit the heartbeat message of the second type.

24. An electronic device, characterized in that: It includes one or more memories and one or more processors; the one or more memories are coupled to the one or more processors, and the one or more memories are used to store computer program codes, and the computer program codes include computer instructions, and when the one or more processors execute the computer instructions, the electronic device executes the method described in any one of claims 1 to 22.

25. A computer-readable storage medium, characterized in that: The computer-readable storage medium comprises a computer program, and when the computer program is executed on an electronic device, the electronic device is caused to execute the method according to any one of claims 1 to 22.

26. A computer program product, characterized in that The computer program product comprises: a computer program or instructions, and when the computer program or instructions are run on a computer, the computer is caused to perform the method according to any one of claims 1 to 22.

Citation Information

Patent Citations

  • Keep-alive method, device and system for data transmission link

    CN103684815A

  • Equipment heartbeat interval control method and device, Internet of Things equipment and storage medium

    CN114500550A