Communication method, system and related device
By sending heartbeat messages on the service connection and determining the second cycle on the detection connection, the increase in power consumption caused by frequent sending heartbeat messages is solved, and the low power consumption and long battery life of the electronic device are achieved.
Patent Information
- Application Number
- CN202410045849.4
- 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-07-01
AI Technical Summary
Frequently sending heartbeat messages leads to an increase in power consumption of electronic devices and affects battery life.
By sending the first type of heartbeat message on the service connection and determining the second cycle on the detection connection, reducing the transmission frequency of the heartbeat message, using different servers to provide service services and detection services, and updating the heartbeat cycle in real time to avoid interruption of business data during the detection process.
It reduces the power consumption of electronic devices, improves battery life, and avoids interruptions in service data transmission.
Smart Images

Figure CN120238560A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of communications, and in particular, to a communication method, system, and related devices. Background Art
[0002] With the continuous development of communication technologies, more and more electronic devices can be connected to the Internet through gateways and communicate with other electronic devices in the Internet.
[0003] The gateway is set with a timeout period. If the communication interval between the electronic device and the gateway exceeds this timeout period, the communication connection between the electronic device and the gateway will be disconnected. Therefore, after establishing a communication connection with the gateway, the electronic device needs to frequently send heartbeat messages to the gateway to avoid the disconnection of this communication connection due to timeout.
[0004] However, frequently sending heartbeat messages will cause power consumption and affect the battery life of the electronic device. Summary of the Invention
[0005] This application provides a communication method, system, and related devices. Based on the detection connection, a new heartbeat period is determined, reducing the sending frequency of heartbeat messages on the service connection, reducing power consumption, and improving the battery life of the electronic device.
[0006] In a first aspect, this application provides a communication method applied to a first electronic device. The method includes: 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, where the second connection is used to transmit a second type of heartbeat message; determines a second period based on the second connection; sends a first type of heartbeat message to the server based on the second period through the first connection; and disconnects the second connection.
[0007] In this way, service data can be transmitted on the first connection (i.e., the service connection), and the heartbeat period can be detected on the second connection (i.e., the detection connection), avoiding the interruption of service data transmission during the detection process.
[0008] 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.
[0009] In this way, different servers in the server set can provide service and detection services respectively, enabling better control of data transmission on different connections.
[0010] In a possible implementation, the second period is greater than the first period.
[0011] In this way, it is possible to reduce the transmission frequency of heartbeat messages in the service connection, reduce power consumption, and improve the battery life.
[0012] In a possible implementation manner, the first electronic device establishes a second connection with the server, which specifically includes: when it is detected that the detection condition is satisfied, 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 since the last detection reaches the 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, a detection instruction is received, and the detection instruction is used to instruct the first electronic device to determine the second period.
[0013] In this way, when the detection condition is satisfied, a detection connection (i.e., the second connection) can be established, and the second period can be determined based on the detection connection.
[0014] In a possible implementation manner, the format of the first type of heartbeat message is the same as that of the second type of heartbeat message; or, the format of the first type of heartbeat message is different from that of the second type of heartbeat message.
[0015] In a possible implementation manner, the content in the first type of heartbeat message is more than that in the second type of heartbeat message. In this way, the transmission power consumption of the second type of heartbeat message can be saved.
[0016] In a possible implementation manner, the moment when the first electronic device establishes the second connection with the server is the first moment; determining the second period based on the second connection specifically includes: at the second moment, sending a first message to the server through the second connection, the first message being a second type of heartbeat message, and the second moment being later than the first moment; receiving a first response, the first response being a response sent by the server in response to the first message through the second connection; when it is detected that the stop condition is satisfied, determining the second period based on the time interval between the first moment and the second moment.
[0017] 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 the fourth constant.
[0018] In this way, when it is detected that the stop condition is satisfied, the second period can be determined based on the heartbeat period corresponding to the most recent successful transmission of a heartbeat message on the second connection.
[0019] In a possible implementation manner, the time interval between the first moment and the second moment is: the product of the first period and the first constant, the first constant being a positive number greater than 1; or, the sum of the first period and the second constant, the second constant being a positive number; or, the average value of the first period and the third constant, the third constant being greater than the first period.
[0020] In this way, the next heartbeat period on the second connection can be determined based on the first period.
[0021] In a possible implementation, the method further includes: 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.
[0022] In this way, after the second connection is disconnected, the second connection can be re - established, and the second period can be determined based on the re - established second connection.
[0023] In a possible implementation, determining the second period based on the second connection specifically includes: at the 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 the fourth moment, sending a fourth message to the server through the second connection, where the fourth message is a heartbeat message of the second type, and the fourth moment is 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 met, determining the second period based on the time interval between the third moment and the fourth moment.
[0024] In a possible implementation, 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 the fourth constant.
[0025] 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 most recent successful heartbeat message sent on the second connection.
[0026] In a possible implementation, the moment when the first electronic device establishes the 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 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.
[0027] In this way, after the second connection is disconnected, the second connection can be re - established, and the second period can be determined based on the re - established second connection.
[0028] In a 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.
[0029] In this way, the next heartbeat period of the second connection can be determined based on the current heartbeat period of the second connection.
[0030] In a possible implementation, before determining the second period based on the second connection, the method further includes: after receiving a 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 a first moment and a third moment.
[0031] In this way, during 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.
[0032] In a possible implementation, before determining the second period based on the second connection, the method further includes: after receiving a 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 difference between the time interval between a first moment and a third moment and a fourth constant.
[0033] In this way, during 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, by introducing a fixed error (i.e., the fourth constant), it is possible to avoid the heartbeat period of the first connection being equal to the timeout time.
[0034] In a possible implementation, 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 second type of heartbeat message; receiving a fifth response, where the fifth response is a response sent by the server in response to the fifth message through the second connection; where the time interval between the fifth moment and the third moment is a third time interval, the time interval between the third moment and the fourth moment is a second time interval, and the third time interval is less than the second time interval.
[0035] In this way, when it is detected that the stop condition is satisfied, the second period can be determined based on the heartbeat period corresponding to the most recent successful heartbeat message sent on the second connection.
[0036] In a 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 a third constant, where the third constant is greater than the third time interval.
[0037] In this way, the next heartbeat period of the second connection can be determined based on the current heartbeat period of the second connection.
[0038] In a possible implementation, before determining the second period based on the second connection, the method further includes: after receiving the third response, sending a heartbeat message of the first type to the server through the first connection based on the 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 the fourth constant.
[0039] In this way, during 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. In addition, a fixed error (i.e., the fourth constant) can be introduced to avoid the heartbeat period of the first connection being equal to the timeout time.
[0040] In a possible implementation, the moment when the first electronic device establishes the second connection with the server is the first moment; determining the second period based on the second connection specifically includes: at the sixth moment, sending a sixth message to the server through the second connection, the sixth message being a heartbeat message of the second type, and the sixth moment being later than the first moment; receiving a sixth response, the sixth response being the response sent by the server through the second connection in response to the sixth message; at the seventh moment, sending a seventh message to the server through the second connection, the seventh message being a heartbeat message of the second type, and 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, determining the second period based on the time interval between the first moment and the sixth moment.
[0041] In a possible implementation, 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 the fourth constant.
[0042] In this way, when it is detected that the stop condition is satisfied, the second period can be determined based on the heartbeat period corresponding to the most recent successful heartbeat message sent on the second connection.
[0043] In a possible implementation, determining a second period based on a second connection specifically includes: at an eighth moment, sending an eighth message to a server through the second connection, where the eighth message is a heartbeat message of a 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, where the ninth message is a heartbeat message of the second type, and the ninth moment is 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, where the tenth message is a heartbeat message of the second type, and the tenth moment is later than the ninth moment; detecting that the second connection is disconnected; when it is detected that a stop condition is satisfied, determining the second period based on the time interval between the eighth moment and the ninth moment.
[0044] In a possible implementation, 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.
[0045] In this way, when it is detected that the stop condition is satisfied, the second period can be determined based on the heartbeat period corresponding to the most recent successful heartbeat message sent on the second connection.
[0046] 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 times of sending heartbeat messages of the second type through the second connection reaches a first number, and the number of times of establishing the second connection reaches a second number.
[0047] In a possible implementation, 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 a first type to the server through the first connection; at a twelfth moment, sending an eleventh message 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, sending a heartbeat message of the first type to the server, and the absolute value of the difference between the fourth time interval and the first period is less than a first threshold.
[0048] In this way, by aligning the sending moments of the heartbeat messages on the first connection and the second connection, the number of times of waking up the first electronic device can be reduced, and the power consumption of the first electronic device can be lowered.
[0049] In a possible implementation, the first electronic device establishing a first connection with the server specifically includes: the first electronic device establishing a first connection with the server through a second electronic device; the first electronic device establishing a second connection with the server specifically includes: the first electronic device establishing a second connection with the server through a second electronic device.
[0050] In this way, the first electronic device can establish a communication connection with the server through the second electronic device.
[0051] In a possible implementation, the method further includes: the first electronic device establishing a third connection with the server; determining a second period based on the second connection, specifically including: determining the second period based on the second connection and the third connection.
[0052] The third connection is used to transmit heartbeat messages of a second type.
[0053] In this way, the second period can be determined based on multiple detection connections.
[0054] In a second aspect, the present application provides an electronic device, which is the first electronic device. 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 code. The computer program code includes computer instructions. When the one or more processors execute the computer instructions, the first electronic device is caused to execute the communication method in any possible implementation of any aspect above.
[0055] In a third aspect, an embodiment of the present application provides a readable storage medium, including instructions. When the instructions run on the first electronic device, the first electronic device is caused to execute the communication method in any possible implementation of any aspect above.
[0056] In a fourth aspect, an embodiment of the present application provides a computer program product. When the computer program product runs on the first electronic device, the first electronic device is caused to execute the communication method in any possible implementation of any aspect above.
[0057] The beneficial effects of the second aspect to the fourth aspect can refer to the beneficial effects of the first aspect above.
[0058] In a 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 the 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 service data and heartbeat messages of a first type, and the second connection is used to transmit heartbeat messages of a second type.
[0059] In this way, different servers in the server set can provide service services and detection services respectively, and can better control data transmission on different connections. BRIEF DESCRIPTION OF THE DRAWINGS
[0060] Figure 1A It is a schematic diagram of the relationship between an intranet, an extranet, and a public network provided by an embodiment of the present application;
[0061] Figure 1B Schematic diagram of the communication connection between an electronic device A1 and a communication network C provided by an embodiment of the present application;
[0062] Figure 2A Schematic diagram of the system architecture of a communication system 10 provided by an embodiment of the present application;
[0063] Figure 2B Schematic diagram of the communication connection between an electronic device 100 and a server 300 provided by an embodiment of the present application;
[0064] Figure 3A Schematic diagram of the hardware structure of an electronic device 100 provided by an embodiment of the present application;
[0065] Figure 3B Schematic diagram of the hardware structure of a server 300 provided by an embodiment of the present application;
[0066] Figure 4 Schematic diagram of the process flow of a communication method provided by an embodiment of the present application;
[0067] Figure 5 Schematic diagram of the process flow for an electronic device 100 to determine a heartbeat period 2 based on a communication connection 2 provided by an embodiment of the present application;
[0068] Figure 6 Schematic diagram of the sending process flow of the service heartbeat message of an electronic device 100 on a communication connection 1 during the process of detecting the heartbeat period 2 provided by an embodiment of the present application;
[0069] Figure 7 Schematic diagram of the moments when an electronic device 100 sends heartbeat messages on a communication connection 1 and a communication connection 2 provided by an embodiment of the present application;
[0070] Figure 8 Schematic diagram of the execution process of a service server 310 and a detection server 320 in a server 300 during the process of detecting the heartbeat period 2 provided by an embodiment of the present application;
[0071] Figure 9 Schematic diagram of the functional modules of a communication system 10 provided by an embodiment of the present application;
[0072] Figure 10 Schematic diagram of the process flow of a communication method provided by an embodiment of the present application. Detailed implementation manners
[0073] The technical solutions in the embodiments of the present application will be clearly and elaborately described below in conjunction with the accompanying drawings. Among them, in the description of the embodiments of the present application, unless otherwise specified, " / " means "or". For example, A / B may represent A or B. The "and / or" in the text is only a description of the association relationship between associated objects, indicating that there can be three relationships. For example, A and / or B may represent: A exists alone, A and B exist simultaneously, and B exists alone. In addition, in the description of the embodiments of the present application, "a plurality of" means two or more than two.
[0074] Hereinafter, the terms "first" and "second" are only used for descriptive purposes and cannot be construed as implying or suggesting relative importance or implicitly indicating the quantity of the indicated technical features. Thus, the features defined with "first" and "second" may explicitly or implicitly include one or more of such features. In the description of the embodiments of the present application, unless otherwise specified, the meaning of "a plurality of" is two or more than two.
[0075] The term "user interface (UI)" in the following embodiments of the present application is a media interface for interaction and information exchange between an application program or an 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 source code written in specific computer languages 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 recognizable by the user. The common manifestation form of the user interface is the graphical user interface (GUI), which refers to the user interface related to computer operations displayed in a graphical manner. It can be visual interface elements such as text, icons, buttons, menus, tabs, text boxes, dialog boxes, status bars, navigation bars, and Widgets displayed on the display screen of an electronic device.
[0076] The following introduces some terms involved in the present application.
[0077] Local area network: A local area network refers to a communication network formed by connecting multiple electronic devices within a certain area. The local area network is closed and can be composed of two or more electronic devices. Through a dedicated data line, the local area network can be connected to a local area network or a database in other places to form a larger information processing system.
[0078] Internal network: If an electronic device is currently in a communication network, then this communication network can be regarded as the internal network of this electronic device. The internal network belongs to the local area network.
[0079] External network: If an electronic device is currently in a communication network, then all other communication networks outside this communication network can be regarded as the external network of the electronic device. Generally speaking, a firewall is set up between the internal network and the external network. What is inside the firewall can be called the internal network, and what is outside the firewall can be called the external network.
[0080] Public network: The communication network that an electronic device in the internal network can access through a gateway can be called a 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. For the specific content of the internal network, external network, and public network, reference can also be made to the relevant descriptions in the following Figure 1A illustrated embodiments.
[0081] Internet Protocol address: The Internet Protocol (IP) address is a unified address format provided by the IP protocol. It assigns a logical address to each network and each host on the Internet to mask the differences in physical addresses. The IP protocol is a protocol designed for computer networks to communicate with each other.
[0082] Internal network IP address: The internal network IP address, also known as the local area network address. An electronic device can communicate with other electronic devices in the internal network through this internal network IP address. The internal network IP address is unique within this internal network.
[0083] Public network IP address: The public network IP address can be used for communication in the public network. The public network IP address is unique in the public network. Since there are a large number of electronic devices in the public network, it is unrealistic to assign a public network IP address to each electronic device in the public network. Therefore, when an electronic device in the internal network accesses the public network through a gateway, it can convert the internal network IP address into a legal public network IP address at the gateway and access the public network based on this public network IP address.
[0084] Network Address Translation: Network Address Translation (NAT) is a conversion technology that converts an internal network IP address into a legal public network IP address. NAT can connect electronic devices in the internal network to the public network and communicate with other electronic devices in the public network. NAT can not only solve the problem of insufficient public network IP addresses, but also effectively avoid attacks from the external network and hide and protect electronic devices in the internal network.
[0085] Gateway: A gateway is a gateway for connecting one communication network to another. Electronic devices within the internal network can access the public network through the gateway, and the gateway can have NAT functionality. In some application scenarios, the gateway can also refer to a device with NAT functionality. It should be noted that electronic devices with NAT functionality such as routers and computers can all be regarded as gateways.
[0086] Timeout: The timeout (aging - time) can also be referred to as the aging time. When an electronic device within the internal network accesses the public network through the gateway, the gateway will configure a legal public network IP address for the electronic device through NAT technology. However, this public network IP address has a timeout. When the duration of non - use of this public network IP address exceeds the timeout, the gateway will age the public network IP address, and at this time, the electronic device can no longer use this public network IP address to access the public network.
[0087] Heartbeat packet: A heartbeat packet refers to data that is transmitted multiple times on a communication connection to maintain the communication connection. In the case where an internal network electronic device accesses the public network through the gateway, the internal network 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 - mentioned timeout, if the public network IP address ages, the communication connection between the electronic device and the public network will be disconnected. Therefore, in order to maintain this communication connection, the electronic device needs to send heartbeat packets multiple times on this communication connection to avoid the aging of the public network IP address and thus avoid the disconnection of this communication connection. In some application scenarios, the heartbeat packet can also be referred to as a heartbeat package.
[0088] Heartbeat period: On a communication connection, an electronic device can send heartbeat packets at a fixed time interval, and this fixed time interval can be referred to as the heartbeat period of this communication connection. It should be noted that the heartbeat period on a communication connection can be changed, that is, within different time periods, the heartbeat periods on the communication connection can be different.
[0089] Low - power state: The low - power state refers to the state where the power consumption of an electronic device is lower than the normal power consumption. In the low - power state, the power consumption of the central processing unit (CPU) or microcontroller unit (MCU) is relatively low, and the CPU (or MCU) needs to be awakened before it can work normally. When an electronic device sends or receives a heartbeat packet, the electronic device can awaken the CPU (or MCU) and switch the electronic device from the low - power state to the working state. In the embodiments of this application, awakening the electronic device means switching the electronic device from the low - power state to the working state.
[0090] Working state: The working state refers to the state in which the power consumption of the electronic device is maintained at the normal power consumption. In the working state, the CPU (or MCU) can work normally.
[0091] The following introduces the relationship between the intranet, extranet, and public network in combination with specific examples.
[0092] Figure 1A A schematic diagram showing the relationship between an intranet, an extranet, and a public network is shown.
[0093] Such as Figure 1A As shown, communication network A may include electronic devices A1 and A2, communication network B may include electronic devices B1 and B2, communication network C may include electronic devices C1 and C2, and communication network C may also include communication networks A and B. Among them:
[0094] Communication network A can be regarded as the intranet of electronic devices A1 and A2, communication network B can be regarded as the extranet of electronic devices A1 and A2, and communication network C can be regarded as the public network of communication network A. Electronic device A2 can be used as a gateway to establish a communication connection with communication network C, so that electronic device A1 can communicate with the electronic devices in communication network C (such as electronic devices C1, C2, and the electronic devices in communication network B, etc.) through electronic device A2.
[0095] Communication network B can be regarded as the intranet of electronic devices B1 and B2, communication network A can be regarded as the extranet of electronic devices B1 and B2, and communication network C can be regarded as the public network of communication network B. Electronic device B1 can be used as a gateway to establish a communication connection with communication network C, so that electronic device B2 can communicate with the electronic devices in communication network C (such as electronic devices C1, C2, and the electronic devices in communication network A, etc.) through electronic device B1.
[0096] It can be understood that Figure 1A The illustrated embodiments are only exemplary illustrations 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 those in the above embodiments, or include more, fewer, or different communication networks than those in the above embodiments. The present application does not make any limitations here.
[0097] The following introduces the method for an electronic device in the intranet to communicate with an electronic device in the public network through a gateway.
[0098] Figure 1B A schematic diagram of the communication connection between electronic device A1 and communication network C is shown.
[0099] Such as Figure 1BAs shown, electronic device A1 and electronic device A2 belong to communication network A. For the relevant descriptions of communication network A and communication network C, reference can be made to the above Figure 1A shown embodiments. Among them, electronic device A2 can act as a gateway, enabling electronic device A1 to connect to communication network C through electronic device A2.
[0100] Electronic device A1 can have an internal network IP address, and electronic device A1 can establish a communication connection with electronic device A2 based on this internal network IP address. Electronic device A2 has the NAT function and can configure a public network IP address for electronic device A1. Based on this public network IP address, electronic device A1 can establish a communication connection with any device in communication network C through electronic device A2.
[0101] According to the above timeout time, the public network IP address configured by electronic device A2 for electronic device A1 has a timeout time. When it has not timed out, 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 based on the public network IP address through electronic device A2; when it times out, electronic device A2 can age the originally configured public network IP address for electronic device A1. At this time, electronic device A1 cannot communicate with communication network C based on the original public network IP address through electronic device A2. After timing out, if electronic device A1 still needs to communicate with the devices in communication network C, electronic device A2 can allocate a new public network IP address for electronic device A1 and establish a communication connection with the devices in communication network C based on the newly allocated public network IP address.
[0102] It can be understood that when there is business data interaction between electronic device A1 and the devices in communication network C, if the communication connection between electronic device A1 and communication network C is disconnected, it will affect the transmission of business data between electronic device A1 and communication network C. Electronic device A1 can send heartbeat messages multiple times through this communication connection to maintain the communication connection between electronic device A1 and communication network C. When the transmission interval between any two adjacent data (such as business data, heartbeat messages, etc.) on this communication connection is less than the timeout time, the disconnection of this communication connection can be avoided.
[0103] In some embodiments, electronic device A1 can set a heartbeat period for this communication connection, and the heartbeat period can be less than the timeout time. Electronic device A1 can send heartbeat messages to communication network C at fixed time intervals based on the heartbeat period through this communication connection. In this way, even if no business data is transmitted on this communication connection for a period of time, electronic device A2 can maintain the communication connection between electronic device A1 and communication network C based on the heartbeat messages.
[0104] It should be noted that when the electronic device A1 is in the low-power state, each time the electronic device A1 sends or receives a heartbeat message, it will cause the electronic device A1 to switch from the low-power state to the working state, and the power consumption required for the electronic device A1 to switch from the low-power state to the working state is relatively large. It can be understood that the smaller the heartbeat period, the more times the electronic device A1 sends heartbeat messages within the same time period, the greater the power consumption of the electronic device A1, and the worse the battery life.
[0105] Therefore, the electronic device A1 needs to determine a heartbeat period that is less than the timeout period and has the smallest difference from the timeout period, so as to reduce the power consumption of the electronic device A1 while maintaining the communication connection.
[0106] In some embodiments, the electronic device A1 may be set with a detection step (such as 30 seconds, 1 minute, etc.). When the electronic device A1 has established a communication connection with the communication network C, the electronic device A1 can determine a new heartbeat period based on the sum of the current heartbeat period and the detection step, and determine whether the updated heartbeat period can maintain the communication connection based on whether each heartbeat message is successfully sent, until the largest heartbeat period that can maintain the communication connection is detected, and the heartbeat message is sent based on the detected heartbeat period to maintain the communication connection. In this way, the heartbeat period on the communication connection increases, and the heartbeat message sending frequency decreases, which can reduce the power consumption of the electronic device A1 and also avoid the disconnection of the communication connection. However, during the process of detecting the largest heartbeat period that can maintain the communication connection, the communication connection may be disconnected, which will affect the transmission of service data.
[0107] The following introduces the system architecture of a communication system 10 provided by an embodiment of the present application.
[0108] Figure 2A FIG. shows a schematic diagram of the system architecture of a communication system 10 provided by an embodiment of the present application.
[0109] As Figure 2A shown, the communication system 10 may include an electronic device 100, an electronic device 200, and a server 300. Among them:
[0110] One or more communication connections may be established between the electronic device 100 and the electronic device 200, such as communication connection A1 and communication connection A2. One or more communication connections may be established between the electronic device 200 and the server 300, such as communication connection B1 and communication connection B2.
[0111] The electronic device 100 can 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 can include the above-mentioned communication connection A1 and communication connection B1, and communication connection 2 can include the above-mentioned communication connection A2 and communication connection B2.
[0112] Communication connection 1 can be used to transmit service data between the electronic device 100 and the server 300. The electronic device 100 can execute corresponding services based on the transmitted service data, such as video playback service, audio playback service, page browsing service, call service, game service, etc. Therefore, in the embodiments of the present application, the communication connection used to transmit service data can also be referred to as a service connection, and communication connection 1 belongs to the service connection. Communication connection 1 can also be used to transmit service heartbeat messages, and the service heartbeat messages are used to maintain communication connection 1 and prevent communication connection 1 from disconnecting due to exceeding the timeout period of the electronic device 200. The electronic device 100 can send service heartbeat messages to the server 300 on communication connection 1 based on heartbeat period 1.
[0113] Communication connection 2 can be used to detect heartbeat period 2. In the embodiments of the present application, the communication connection used to detect heartbeat period 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 detection heartbeat messages. The detection heartbeat messages are used to detect heartbeat period 2. The electronic device 100 can determine heartbeat period 2 by changing the sending time interval of the detection heartbeat messages and whether each detection heartbeat message is successfully sent. It can be understood that during the process of detecting heartbeat period 2, communication connection 2 may be disconnected and re-established one or more times. In other embodiments, the detection connection between the electronic device 100 and the server 300 can also include multiple communication connections. At this time, the electronic device 100 can detect heartbeat period 2 through these multiple communication connections, and the present application does not make any limitations here.
[0114] After determining heartbeat period 2, the electronic device 100 can change the period of sending heartbeat messages on the service connection (such as communication connection 1) to heartbeat period 2, and can also disconnect the detection connection (such as communication connection 2).
[0115] The electronic device 200 can act as a gateway to convert the internal network IP address of the electronic device 100 into a public network IP address and connect the electronic device 100 and the server 300. In other embodiments, the electronic device 200 can also connect the electronic device 100 and 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 make any limitations on the device type of the electronic device 200.
[0116] 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 in this server cluster, each server may have different functions, which is not limited in this application. For the specific content of the server 300, reference may also be made to the relevant descriptions in the following Figure 2B illustrated embodiments, which will not be elaborated here for the time being.
[0117] It can be understood that the above Figure 2A illustrated embodiments are only examples. In some embodiments, there may be more devices (such as routers, etc.) 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 embodiments, which is not limited in this application.
[0118] Figure 2B FIG. shows a schematic diagram of the communication connection between an electronic device 100 and a server 300 provided by an embodiment of the present application.
[0119] As Figure 2B shown, the server 300 may include a service server 310 and a detection server 320.
[0120] In some embodiments, the server 300 may include multiple server modules. At this time, the service 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.
[0121] In other embodiments, the server 300 may be a server cluster including multiple servers. At this time, the service 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.
[0122] In the server 300, the service server 310 may provide service for the electronic device 100. The service server 300 may establish a service connection with the electronic device 100 through the electronic device 200 (such as the communication connection 1 in the above Figure 2A illustrated embodiment), and send and receive service data through this service connection, so that the electronic device 100 can execute corresponding services, such as video playback service, audio playback service, call service, game service, page browsing service, etc. The detection server 320 may establish one or more detection connections with the electronic device 100 through the electronic device 200, such as the communication connection 2 in the above Figure 2A illustrated embodiment. The electronic device 100 may determine the heartbeat period 2 based on the one or more detection connections.
[0123] In this way, different server modules in the server 300 can provide service services and detection services for the electronic device 100 respectively, isolating the detection service from the service service, which is convenient for the server 300 to better control the data transmission on the service connection and the detection connection.
[0124] It can be understood that the above Figure 2B illustrated embodiment is only an example. In the embodiments of the present application, the server 300 may also include more, fewer or different server modules (or servers) than the above Figure 2B illustrated embodiment, and the present application does not make any limitation here.
[0125] It should be noted that in some other embodiments, the server 300 may not include the detection server 320. In this case, the service server 310 can establish a service connection and a detection connection with the electronic device 100 through the electronic device 200. The service server 310 can control the service connection to send and receive service data, and control the detection connection to receive the detection heartbeat message sent by the electronic device 100.
[0126] Next, a hardware structure of an electronic device 100 provided in the embodiments of the present application is introduced.
[0127] Figure 3A FIG. shows a schematic diagram of the hardware structure of an electronic device 100 provided in the embodiments of the present application.
[0128] 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, as well as 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, a vehicle-mounted 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.
[0129] 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 further 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. Among them, the sensor module 180 may include a touch sensor 180K. Optionally, the sensor module 180 may further include any one or more of the following: a pressure sensor, a gyroscope sensor, a barometric 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.
[0130] It can be understood that the structure illustrated in the embodiments 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 those illustrated, or combine certain components, or split certain components, or have different component arrangements. The illustrated components may be implemented in hardware, software, or a combination of software and hardware.
[0131] 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 processing unit (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. Among them, different processing units may be independent devices or integrated in one or more processors.
[0132] The controller may generate operation control signals according to the instruction operation code and timing signals to complete the control of fetching instructions and executing instructions.
[0133] A memory can also be provided in the processor 110 for storing instructions and data. In some embodiments, the memory in the processor 110 is a cache memory. This memory can hold the instructions or data that the processor 110 has just used or recycled. If the processor 110 needs to use the instruction or data again, it can be directly retrieved from the memory. This avoids repeated accesses and reduces the waiting time of the processor 110, thus improving the efficiency of the system.
[0134] In some embodiments, the processor 110 may include one or more interfaces. The interfaces 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.
[0135] The charging management module 140 is configured to receive a charging input from a charger. The charger can be a wireless charger or a wired charger. In some embodiments of wired charging, the charging management module 140 can receive the charging input from the wired charger through the USB interface 130. In some embodiments of wireless charging, the charging management module 140 can receive the wireless charging input through the wireless charging coil of the electronic device 100. While charging the battery 142, the charging management module 140 can also supply power to the electronic device through the power management module 141.
[0136] 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 inputs from the battery 142 and / or the charging management module 140 and supplies power to the processor 110, the internal memory 121, the display screen 194, the wireless communication module 160, etc. The power management module 141 can also be used to monitor parameters such as the battery capacity, the number of battery cycles, and the battery health status (leakage, impedance). In some other embodiments, the power management module 141 can also be disposed in the processor 110. In some other embodiments, the power management module 141 and the charging management module 140 can also be disposed in the same device.
[0137] The wireless communication function of the electronic device 100 can be implemented by the antenna 1, the antenna 2, the mobile communication module 150, the wireless communication module 160, the modulation and demodulation processor, and the baseband processor, etc.
[0138] The antenna 1 and the antenna 2 are used to transmit and receive electromagnetic wave signals. Each antenna in the electronic device 100 can be used to cover a single or multiple communication frequency bands. Different antennas can also be multiplexed to improve the utilization rate of the antennas. For example: The antenna 1 can be multiplexed as the diversity antenna of the wireless local area network. In some other embodiments, the antenna can be used in combination with a tuning switch.
[0139] The mobile communication module 150 can provide solutions for wireless communications such as 2G / 3G / 4G / 5G applied to the electronic device 100. The mobile communication module 150 can include at least one filter, switch, power amplifier, low noise amplifier (LNA), etc. The mobile communication module 150 can receive electromagnetic waves by the antenna 1, filter, amplify, etc. 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 through the antenna 1 for radiation. In some embodiments, at least some functional modules of the mobile communication module 150 can be disposed in the processor 110. In some embodiments, at least some functional modules of the mobile communication module 150 and at least some modules of the processor 110 can be disposed in the same device.
[0140] The modulation and demodulation processor may include a modulator and a demodulator. Among them, the modulator is used to modulate the low-frequency baseband signal to be transmitted into a medium-high frequency signal. The demodulator is used to demodulate the received electromagnetic wave signal into a low-frequency baseband signal. Subsequently, the demodulator transmits the demodulated low-frequency baseband signal to the baseband processor for processing. After being processed by the baseband processor, the low-frequency baseband signal is transmitted to the application processor. The application processor outputs a sound signal through an audio device (not limited to the speaker 170A, the receiver 170B, etc.), or displays an image or video through the display screen 194. In some embodiments, the modulation and demodulation processor may be an independent device. In other embodiments, the modulation and demodulation processor may be independent of the processor 110 and be provided in the same device as the mobile communication module 150 or other functional modules.
[0141] The wireless communication module 160 may provide solutions for wireless communications applied to the electronic device 100, including wireless local area networks (WLANs) (such as wireless fidelity (Wi-Fi) networks), Bluetooth (BT), global navigation satellite systems (GNSS), frequency modulation (FM), near field communication (NFC), infrared technology (IR), etc. The wireless communication module 160 may 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 signal, and transmits the processed signal to the processor 110. The wireless communication module 160 may also receive the signal to be transmitted from the processor 110, frequency-modulate it, amplify it, and convert it into electromagnetic waves through the antenna 2 for radiation.
[0142] In some embodiments, antenna 1 of electronic device 100 is coupled to mobile communication module 150, and antenna 2 is coupled to wireless communication module 160, such that electronic device 100 can communicate with a network and other devices through wireless communication technologies. The wireless communication technologies 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 technologies, etc. The GNSS may include global positioning system (GPS), global navigation satellite system (GLONASS), beidou navigation satellite system (BDS), quasi-zenith satellite system (QZSS), and / or satellite based augmentation systems (SBAS).
[0143] Electronic device 100 implements a display function through a GPU, display screen 194, and an application processor, etc. The GPU is a microprocessor for image processing, and is connected to display screen 194 and the application processor. The GPU is used to perform mathematical and geometric calculations for graphics rendering. Processor 110 may include one or more GPUs, which execute program instructions to generate or change display information.
[0144] 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 can also be an organic light-emitting diode (OLED), an active-matrix organic light-emitting diode (AMOLED), a flexible light-emitting diode (FLED), a MiniLED, a MicroLED, a Micro-OLED, a quantum dot light-emitting diode (QLED), etc. In some embodiments, the electronic device 100 may include one or N display screens 194, where N is a positive integer greater than 1.
[0145] The internal memory 121 may include one or more random access memories (RAM) and one or more non-volatile memories (NVM).
[0146] The random access memory can be directly read and written by the processor 110, and can be used to store the operating system or executable programs of other running programs (such as machine instructions), and can also be used to store data of users and application programs, etc.
[0147] The non-volatile memory can also store executable programs and store data of users and application programs, etc., and can be pre-loaded into the random access memory for the processor 110 to directly read and write.
[0148] 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 the data storage function. For example, files such as music and videos are saved in the external non-volatile memory.
[0149] 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 can implement audio functions through the audio module 170 and an application processor, etc. Such as music playback, recording, etc.
[0150] The audio module 170 is used to convert digital audio information into an analog audio signal for output, and is also used to convert an analog audio input into a digital audio signal. The audio module 170 can also be used to encode and decode audio signals. In some embodiments, the audio module 170 can be disposed in the processor 110, or some functional modules of the audio module 170 can be disposed in the processor 110.
[0151] The speaker 170A, also known as the "loudspeaker", is used to convert an audio electrical signal into a sound signal. The electronic device 100 can listen to music or a hands-free call through the speaker 170A.
[0152] The receiver 170B, also known as the "earpiece", is used to convert an audio electrical signal into a sound signal. When the electronic device 100 answers a call or a voice message, the voice can be listened to by holding the receiver 170B close to the ear.
[0153] The microphone 170C, also known as the "microphone" or "transmitter", is used to convert a sound signal into an electrical signal. When making a call or sending a voice message, the user can speak by bringing the mouth close to the microphone 170C to input the sound signal into the microphone 170C. The electronic device 100 can be provided with at least one microphone 170C. In some other embodiments, the electronic device 100 can be provided with two microphones 170C, which can not only collect sound signals but also implement a noise reduction function. In some 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, and implement functions such as directional recording.
[0154] The touch sensor 180K, also known as the "touch control device". The touch sensor 180K can be disposed on the display screen 194, and the touch sensor 180K and the display screen 194 together form a touch screen, also known as the "touch control screen". The touch sensor 180K is used to detect touch operations acting thereon or nearby. The touch sensor can transmit the detected touch operations to the application processor to determine the type of touch event. Visual outputs related to the touch operations can be provided through the display screen 194. In some other embodiments, the touch sensor 180K can also be disposed on the surface of the electronic device 100 at a position different from that of the display screen 194.
[0155] The keys 190 include a power-on key, volume keys, etc. The keys 190 can be mechanical keys or touch keys. The electronic device 100 can receive key inputs to generate key signal inputs related to the user settings and function controls of the electronic device 100.
[0156] The motor 191 can generate vibration prompts. The motor 191 can be used for incoming call vibration prompts and also for touch vibration feedback. For example, touch operations for different applications (such as taking pictures, audio playing, etc.) can correspond to different vibration feedback effects. For touch operations on different areas of the display screen 194, the motor 191 can also correspond to different vibration feedback effects. Different application scenarios (such as time reminder, receiving messages, alarm clock, games, etc.) can also correspond to different vibration feedback effects. The touch vibration feedback effect can also support customization.
[0157] The indicator 192 can be an indicator light and can be used to indicate the charging state, power change, and can also be used to indicate messages, missed calls, notifications, etc.
[0158] It can be understood that in some embodiments, the hardware structure of the electronic device 200 can also refer to Figure 3A the hardware structure of the electronic device 100 shown. In other embodiments, the electronic device 200 may include fewer, more, or different components from those in the above Figure 3A shown embodiments, and the present application does not make any limitations here.
[0159] Figure 3B This is a schematic diagram of the hardware structure of a server 300 provided by an embodiment of the present application.
[0160] As Figure 3B 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 can be connected through a bus 304 or other means. Figure 3B Taking the connection through the bus as an example. Among them:
[0161] 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 wireless communication interfaces, the server 300 can also be configured with a wired communication interface 303 to support wired communication.
[0162] 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 perform transmission processing on the signals output by the network device processor 301. The receiver 306 can be used to receive signals. In the server 300, the number of the transmitter 305 and the receiver 306 can each be one or more. The antenna 308 can be used to convert the electromagnetic energy in the transmission line into electromagnetic waves in free space, or convert the electromagnetic waves in 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 them to multiple receivers 306. It can be understood that the antenna 308 of the network device can be implemented as a massive antenna array.
[0163] 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 can include a high-speed random access memory, and can 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.
[0164] The memory 302 can store an operating system (hereinafter referred to as the system), such as an embedded operating system like uCOS, VxWorks, RTLinux, etc. The memory 302 can also store a network communication program, which can be used to communicate with other communication devices.
[0165] In the embodiments 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 the implementation program of the communication method provided by one or more embodiments of the present application, and execute the instructions included in the program.
[0166] It can be understood that Figure 3B The illustrated embodiments are only examples. In the embodiments of the present application, the server 300 may further include more, fewer or different devices than those in the above embodiments, and the present application does not make any limitations here. It should be noted that in some 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) can also refer to the relevant descriptions in the Figure 3B illustrated embodiments above, which will not be elaborated here.
[0167] The present application provides a communication method. The electronic device 100 can establish a communication connection 1 with the server 300, and based on the communication connection 1, the electronic device 100 can interact with the server 300 for service data. The electronic device 100 sends a service heartbeat message to the server 300 based on a heartbeat period 1 over the communication connection 1. The electronic device 100 can also establish a communication connection 2 with the server 300 and send a probe heartbeat message to the server 300 through the communication connection 2. The electronic device 100 can determine a heartbeat period 2 based on the communication connection 2. After determining the heartbeat period 2, the electronic device 100 can send a service heartbeat message to the server 300 based on the heartbeat period 2 over the communication connection 1 and disconnect the communication connection 2.
[0168] In this way, the electronic device 100 can maintain the communication connection 1 based on the heartbeat period 2 determined on the communication connection 2, reducing the power consumption caused by the sending of heartbeat messages. Moreover, during the process of determining the heartbeat period 2, the communication connection 1 is always maintained, and service data is transmitted over the communication connection 1, which can avoid the interruption of service data during the probing process.
[0169] Figure 4 The flowchart shows a communication method provided by an embodiment of the present application.
[0170] As Figure 4 shown, the specific process of the communication method may include the following steps:
[0171] 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 based on a heartbeat period 1 through the communication connection 1.
[0172] In some embodiments, the specific manner for the electronic device 100 to establish a communication connection (such as communication connection 1, communication connection 2, etc.) with the server 300 may refer to the establishment manner of a TCP long connection, which is not elaborated herein in the present application.
[0173] 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 for sending and receiving service data so that the electronic device 100 can perform corresponding services (such as video playback service, audio playback service, page browsing service, chat service, game service, etc.).
[0174] In the embodiments of the present application, the heartbeat message sent over the communication connection 1 can be called a service heartbeat message, and the heartbeat message sent over the communication connection 2 (or other probing connections) can be called a probe heartbeat message.
[0175] The content composition of the service heartbeat message and the probe heartbeat message is introduced below.
[0176] Exemplarily, Table 1 shows the content composition of the service heartbeat message sent on the service connection and the probe heartbeat message sent on the probe connection.
[0177] Table 1
[0178]
[0179] As shown in Table 1, the service heartbeat message sent on the service connection may include the following content: encryption protocol, device registration information, authentication information, key information, heartbeat message identification number, etc. The probe heartbeat message sent on the probe connection may include the heartbeat message identification number. Optionally, it 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 represent the permissions of the electronic device 100. For example, it is used to indicate whether the electronic device 100 has the permission 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. It can be seen from Table 1 that the number of fields in the service heartbeat message can be M1, and the number of fields in the probe heartbeat message can be M2. M1 can be greater than or equal to M2. Exemplarily, M1 can be 3 and M2 can be 1.
[0180] It can be understood that the embodiment shown in Table 1 is only an example. In other embodiments, the service heartbeat message and the probe heartbeat message may also include more, less, or different content from the above embodiments, and the present application does not make any limitations here.
[0181] In other embodiments, the content composition of the probe heartbeat message may also be the same as that of the service heartbeat message, and the present application does not make any limitations here.
[0182] It should be noted that after the electronic device 100 establishes the communication connection 1 with the server 300, in order to maintain this communication connection 1, the electronic device 100 may send multiple service heartbeat messages to the server 300 through this communication connection.
[0183] The heartbeat period 1 can be a preset time length, such as 5 seconds, 30 seconds, 3 minutes, 5 minutes, etc.
[0184] In some embodiments, after the electronic device 100 establishes the communication connection 1, it can send service heartbeat messages to the server 300 at a fixed time interval through the communication connection 1, so as to avoid the disconnection of the communication connection 1. This fixed time interval is the time length corresponding to the heartbeat period 1.
[0185] In some other embodiments, after establishing communication connection 1, the electronic device 100 may first send service heartbeat messages based on heartbeat period 1, then update the heartbeat period of communication connection 1 based on the detection results on communication connection 2 subsequently, and send service heartbeat messages based on the updated heartbeat period. The update method of the heartbeat period of communication connection 1 may refer to the relevant descriptions in the following Figure 6 illustrated embodiments, which will not be elaborated here for the time being.
[0186] S402. When the detection condition is met, the electronic device 100 establishes communication connection 2 with the server 300.
[0187] The detection condition may include but is not limited to any one or more of the following: the electronic device 100 connects to a communication network for the first time, the duration since the last detection of the heartbeat period on the electronic device 100 reaches a preset duration (such as 5 days, 10 days, or 14 days, etc.), the electronic device 100 receives an operation from the user to detect the heartbeat period, the electronic device 100 receives a detection instruction sent by another electronic device, and the detection instruction is used to instruct the electronic device 100 to detect the heartbeat period, etc.
[0188] When detecting that the detection condition is met, the electronic device 100 may establish one or more detection connections with the server 300 through the electronic device 200, and the one or more detection connections may be used to detect heartbeat period 2.
[0189] In some embodiments, the one or more detection connections may include communication connection 2.
[0190] In some other embodiments, the one or more detection connections may also include communication connection 2 and other communication connections, which are not limited in this application.
[0191] S403. The electronic device 100 determines heartbeat period 2 based on communication connection 2.
[0192] The electronic device 100 may determine heartbeat period 2 on communication connection 2 by any method such as the dichotomy method, the step-by-step long detection method, the exponential detection method, etc.
[0193] Exemplarily, Figure 5 shows a schematic flowchart of an electronic device 100 provided by an embodiment of the present application for determining heartbeat period 2 based on communication connection 2.
[0194] S501. The electronic device 100 determines a detection interval, and the detection interval includes a detection upper limit and / or a detection lower limit.
[0195] The electronic device 100 may first determine a detection interval. The detection interval may include a detection upper limit and / or a detection lower limit.
[0196] In some embodiments, the electronic device 100 may determine the lower detection limit of the detection interval based on the heartbeat period 1 in step S401. For example, if the heartbeat period 1 is T0, the lower detection limit is determined to be T0. After determining the lower detection limit, the electronic device 100 may determine the detection interval as [T0, +∞], or determine the detection interval as [T0, K*T0], where K is a preset positive number.
[0197] It can be understood that this is just an example here. In the embodiments of the present application, the electronic device 100 may also determine the detection interval based on other preset time thresholds, or determine a detection interval different from that of the above embodiments in a manner different from the above embodiments, and the present application does not limit this here.
[0198] 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.
[0199] The detection interval includes an upper detection limit and / or a lower detection limit. The electronic device 100 may 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 may calculate the heartbeat period of the communication connection 2 using any one of the following formulas (1) to (3).
[0200] Heartbeat period = (Upper detection limit + Lower detection limit) / 2 Formula (1)
[0201] In the above formula (1), the heartbeat period may be the average of the upper detection limit and the lower detection limit.
[0202] Heartbeat period = Lower detection limit + Step size Formula (2)
[0203] In the above formula (2), the heartbeat period may be the sum of the lower detection limit and the step size. Among them, the step size may be a preset duration (such as 30 seconds, 60 seconds, etc.).
[0204] Heartbeat period = Lower detection limit * a Formula (3)
[0205] In the above formula (3), the heartbeat period may be the product of the lower detection limit and the constant a, and the constant a is a positive number greater than 1.
[0206] It can be understood that the embodiments here are just three examples. In some 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 here.
[0207] It should be noted that steps S502 to S508 are steps that can be repeatedly executed. In some embodiments, the electronic device 100 may 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 may also update the heartbeat period of the communication connection 2 in different manners each time step S502 is executed. For example, when step S502 is executed for the first time, the heartbeat period of the communication connection 2 is updated in the manner shown in formula (3), and when step S502 is executed for the second time, the heartbeat period of the communication connection 2 is updated in the manner shown in formula (1), and so on. It can be understood that the embodiments herein are only illustrative. Each time step S502 is executed, the update manner of the heartbeat period of the communication connection 2 may be the same or different, and the present application does not make any limitation here.
[0208] S503. The electronic device 100 determines the next heartbeat time based on the heartbeat period of the communication connection 2.
[0209] In Figure 5 the illustrated embodiment, the next heartbeat time refers to the next sending time of the detection heartbeat message.
[0210] The electronic device 100 may determine the next heartbeat time based on the following formula (4).
[0211] Next heartbeat time = heartbeat period + previous heartbeat time Formula (4)
[0212] In the above formula (4), the next heartbeat time can be determined based on the heartbeat period and the previous heartbeat time.
[0213] It should be noted that if the next heartbeat is the first heartbeat, the previous heartbeat time can be replaced with the establishment time of the communication connection 2.
[0214] S504. When the next heartbeat time arrives, the electronic device 100 sends a detection heartbeat message through the communication connection 2.
[0215] For the specific content of the detection heartbeat message, reference can be made to the relevant description in the embodiment shown in Table 1 above.
[0216] In some embodiments, the detection heartbeat message may further include heartbeat time information (such as the next heartbeat period, etc.). The heartbeat time information is used to determine the next heartbeat time after the current heartbeat time. The present application does not make any limitation here. For details, reference can be made to the relevant description in the following Figure 8 illustrated embodiment, and details are not described here for the time being.
[0217] S505. The electronic device 100 determines whether the communication connection 2 is disconnected.
[0218] When the communication connection 2 is not disconnected, the electronic device 100 can receive a response message returned by the server 300 for the probing heartbeat message. In some embodiments, the response message may also carry a transmission sequence number. The transmission sequence number can be used to indicate the transmission order of the probing heartbeat message corresponding to the response message. The electronic device 100 can determine whether the communication connection 2 is not disconnected based on whether it receives the response message corresponding to the probing heartbeat message.
[0219] If the communication connection 2 is disconnected, it indicates that the current heartbeat period may be greater than the timeout period.
[0220] If the communication connection 2 is not disconnected, it indicates that the current heartbeat period is less than or equal to the timeout period.
[0221] When the electronic device 100 determines that the communication connection 2 is disconnected, the electronic device 100 can perform the following step S506.
[0222] When the electronic device 100 determines that the communication connection 2 is not disconnected, the electronic device 100 can perform the following step S507.
[0223] S506. The electronic device 100 updates the upper limit of the probing range and re - establishes the communication connection 2 with the server 300.
[0224] If the communication connection 2 is disconnected, it indicates that the current heartbeat period is greater than the timeout period of the electronic device 200. At this time, the current heartbeat period can be determined as the upper limit of the probing range.
[0225] After performing step S506, the electronic device 100 can perform the following step S508.
[0226] S507. The electronic device 100 updates the lower limit of the probing range.
[0227] If the communication connection 2 is not disconnected, it indicates that the current heartbeat period is less than or equal to the timeout period of the electronic device 200. At this time, the current heartbeat period can be determined as the lower limit of the probing range.
[0228] 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 messages sent each time on this communication connection may be sent successfully or may be sent failed. To avoid the disconnection of the communication connection, 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.
[0229] In some embodiments, to avoid the situation where the heartbeat period 2 is equal to the timeout, the electronic device 100 may also subtract a constant (such as 10 seconds, 5 seconds, etc.) from the heartbeat period, and update the difference between the heartbeat period and the constant as the lower limit of the detection range of the detection interval. In this way, by introducing a fixed error, it is possible to avoid the detected heartbeat period 2 being equal to the timeout and improve the stability of the detection result.
[0230] After executing step S507, the electronic device 100 may execute the following step S508.
[0231] S508. The electronic device 100 determines whether the stop condition is satisfied.
[0232] The stop condition may include but is not limited to any one or more of the following: the difference between the upper detection limit and the lower detection limit is less than a preset value, the detection time length is greater than a preset duration, the update times of the detection interval are greater than a preset number, etc.
[0233] If the electronic device 100 determines that the stop condition is satisfied, the electronic device 100 may execute the following step S509.
[0234] If the electronic device 100 determines that the stop condition is not satisfied, the electronic device 100 may re-execute the above step S502.
[0235] S509. The electronic device 100 determines the heartbeat period 2 based on the detection interval.
[0236] In some embodiments, the electronic device 100 may determine the lower limit of the current detection interval as the heartbeat period 2.
[0237] It can be understood that Figure 5 The illustrated embodiment is only an example. In some other embodiments, the electronic device 100 may also determine the heartbeat period 2 in a manner different from that of Figure 5 the illustrated embodiment, and the present application does not make any limitation here.
[0238] It should be noted that if there are multiple detection connections established between the electronic device 100 and the server 300, the electronic device 100 may adopt different heartbeat period update methods on different detection connections, and determine the heartbeat period 2 based on the detection results of the multiple detection connections. The specific method may refer to the relevant content in the following Figure 6 illustrated embodiment, which will not be elaborated here for the time being.
[0239] S404. The electronic device 100 disconnects the communication connection 2 with the server 300.
[0240] It should be noted that after executing step S403, the electronic device 100 can execute step S404 and step S405 simultaneously, or execute step S404 first and then step S405, or execute step S405 first and then step S404. This application does not limit the execution order of step S404 and step S405.
[0241] After determining the heartbeat period 2, the electronic device 100 can disconnect the communication connection 2.
[0242] In some embodiments, if the detection connection includes multiple communication connections, after determining the heartbeat period 2, the electronic device 100 can disconnect all detection connections.
[0243] S405. The electronic device 100 sends a service heartbeat message to the server 300 based on the heartbeat period 2 through the communication connection 1.
[0244] After determining the heartbeat period 2, the electronic device 100 can reset the heartbeat period of the communication connection 1 and set the heartbeat period of the communication connection 1 to the heartbeat period 2.
[0245] In this way, the electronic device 100 can maintain the communication connection 1 based on the heartbeat period 2, reducing the power consumption caused by the sending of heartbeat messages. Moreover, during the process of detecting the heartbeat period 2, the communication connection 1 is always maintained, and the service data is transmitted on the communication connection 1, which can avoid the interruption of service data during the detection process.
[0246] In a possible implementation manner, after establishing the communication connection 1, the electronic device 100 can continuously update the heartbeat period of the communication connection 1 based on the detection result during the process of detecting the heartbeat period 2, and send a service heartbeat message based on the updated heartbeat period.
[0247] Exemplarily, Figure 6 shows a schematic diagram of the sending process of the service heartbeat message of the electronic device 100 on the communication connection 1 during the process of detecting the heartbeat period 2 provided by an embodiment of the present application.
[0248] As Figure 6 shown, during the process of detecting the heartbeat period 2, the sending process of the service heartbeat message of the electronic device 100 on the communication connection 1 may include the following steps:
[0249] S601. The electronic device 100 updates the maximum heartbeat period Tmax based on the detection result on the communication connection 2.
[0250] During the process of detecting the heartbeat period 2 based on the communication connection 2, the electronic device 100 can detect one or more available heartbeat periods. An available heartbeat period refers to a heartbeat period that can maintain the communication connection between the electronic device 100 and the server 300, that is, the heartbeat period is less than the timeout period.
[0251] In some embodiments, the electronic device 100 may store a maximum heartbeat period Tmax, which refers to the heartbeat period with the largest value among all detected available heartbeat periods.
[0252] In some embodiments, the electronic device 100 may store a heartbeat period table, and the heartbeat period table may include the maximum heartbeat period Tmax. The maximum heartbeat period Tmax may be the largest available heartbeat period currently detected.
[0253] Exemplarily, Table 2 shows a heartbeat period table stored in the electronic device 100 provided by an embodiment of the present application.
[0254] Table 2
[0255] Maximum heart beat period Tmax = T1 Detection upper limit T2 Detection lower limit T1
[0256] As shown in Table 2, the heartbeat period table stored in the electronic device 100 may include the maximum heartbeat period. Optionally, it may further include a detection upper limit and a detection lower limit, and the detection upper limit and the detection lower limit may be the two ends of the detection interval in the above Figure 5 shown embodiments. According to Table 2, the maximum heartbeat period Tmax may take T1, the detection upper limit may be T2, and the detection lower limit may be T1.
[0257] It can be understood that the embodiment shown in Table 2 is only an example. In the embodiments of the present application, the heartbeat period table may further include more, less, or different content from the above embodiments, and the present application does not make any limitations here.
[0258] In a possible implementation manner, when the electronic device 100 detects a new available heartbeat period, and the value of the available heartbeat period is greater than the currently stored maximum heartbeat period Tmax, the electronic device 100 may update the value of the maximum heartbeat period Tmax, that is, determine the value of Tmax as the new available heartbeat period.
[0259] Exemplarily, if the electronic device 100 determines that the heartbeat period T3 is an available heartbeat period through the communication connection 2, and T3 is greater than T1, the electronic device 100 may update the heartbeat period table shown in Table 2 above to the heartbeat period table shown in Table 3 below.
[0260] Table 3
[0261] Maximum heart beat period Tmax = T3 Detection upper limit T2 Detection lower limit T3
[0262] As shown in Table 3, the heartbeat cycle table stored in the electronic device 100 may include a maximum heartbeat cycle. Optionally, it may further include a detection upper limit and a detection lower limit. According to Table 3, the maximum heartbeat cycle Tmax may take T3, the detection upper limit may be T2, and the detection lower limit may be T3. That is, the values of the maximum heartbeat cycle and the detection lower limit in the heartbeat cycle table may both be updated to T3.
[0263] 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 further include more, less, or different content from the above embodiments, and the present application does not make any limitations here.
[0264] 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.
[0265] In Figure 6 the embodiment shown, the next heartbeat time refers to the time when the electronic device 100 next sends a service heartbeat message through the communication connection 1.
[0266] The electronic device 100 may determine the next heartbeat time based on the heartbeat cycle of the communication connection 1 and the previous heartbeat time. It should be noted that if the next heartbeat is the first heartbeat, the electronic device 100 may determine the next heartbeat time based on the heartbeat cycle of the communication connection 1 and the establishment time of the communication connection 1.
[0267] After executing step S602, the electronic device 100 may execute the following step S603.
[0268] S603. When the next heartbeat time arrives, the electronic device 100 determines whether the maximum heartbeat cycle Tmax is greater than the heartbeat cycle of the communication connection 1.
[0269] If the maximum heartbeat cycle Tmax is greater than the heartbeat cycle of the communication connection 1, the electronic device 100 may execute the following step S604 to update the heartbeat cycle of the communication connection 1.
[0270] If the maximum heartbeat cycle Tmax is less than or equal to the heartbeat cycle of the communication connection 1, the electronic device 100 may execute the following step S605.
[0271] S604. The electronic device 100 determines that the heartbeat cycle of the communication connection 1 is the maximum heartbeat cycle Tmax.
[0272] After executing step S604, the electronic device 100 may execute the above step S602.
[0273] The electronic device 100 sends a service heartbeat message to the server 300 through the communication connection 1.
[0274] After executing step S605, the electronic device 100 may execute the above step S602.
[0275] It can be understood that Figure 6 The illustrated embodiments are only exemplary. During the process of detecting the heartbeat period 2, the electronic device 100 may update the heartbeat period of the service connection based on the detection results on the detection connection. In the embodiments of the present application, the detection connection may also include more communication connections than the above embodiments, and the update method of the heartbeat period on the service connection may also be different from the above embodiments. The present application does not make any limitations here.
[0276] In this way, during the process of detecting the heartbeat period 2, the electronic device 100 may update the heartbeat period of the communication connection 1 based on the detection results on the communication connection 2, thereby reducing power consumption and improving the battery life of the electronic device 100.
[0277] In another possible implementation, the electronic device 100 may also update the heartbeat period of the communication connection 1 synchronously after updating the maximum heartbeat period Tmax based on the detection results on the communication connection 2, and send a service heartbeat message on the communication connection 1 based on the updated heartbeat period. The present application does not make any limitations here.
[0278] In a possible implementation, during the process of detecting the heartbeat period 2 by the electronic device 100 based on the communication connection 2, if the difference between the next sending time of the service heartbeat message on the communication connection 1 and the next sending time of the detection heartbeat message on the communication connection 2 belongs to 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 may control the communication connection 1 and the communication connection 2 to send the service heartbeat message and the detection heartbeat message at the same time.
[0279] In this way, if the electronic device 100 is in a low-power state (or screen-off state), only one wake-up of the electronic device 100 is required to complete the sending of the service heartbeat message and the detection heartbeat message, reducing the number of times of waking up the electronic device 100, reducing the power consumption of the electronic device 100, and thus improving the battery life of the electronic device 100.
[0280] Next, a communication method provided by the embodiments of the present application will be introduced with specific examples.
[0281] Such as Figure 7As shown, the moments when the electronic device 100 sends multiple service heartbeat messages on communication link 1 can be displayed in a one-dimensional coordinate system OX1, and the moments when the electronic device 100 sends multiple probe heartbeat messages on communication link 2 can be displayed in a 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 axes X1 and X2 correspond one by one.
[0282] On the horizontal axis X1, a triangle can represent the sending of a single service heartbeat message. On the horizontal axis X2, a circle can represent the establishment of communication link 2, a hollow triangle can represent the sending of a single probe heartbeat message, and a solid triangle can represent the failure of the sending of that probe heartbeat message.
[0283] According to Figure 7 it can be known that the interaction between the electronic device 100 and the server 300 on communication links 1 and 2 can include the following steps:
[0284] 1. At time t0, the electronic device 100 has established communication link 1 with the server 300.
[0285] 2. From time t0 to time t1, the electronic device 100 sends service heartbeat messages to the server 300 on communication link 1 based on the heartbeat period T.
[0286] The time interval between time t0 and time t1 can be 2T.
[0287] 3. At time t1, the electronic device 100 detects that the probing condition is met and establishes communication link 2 with the server 300.
[0288] Communication link 2 is a probing link, and no service data is transmitted on communication link 2.
[0289] 4. From time t1 to time t2, the electronic device 100 sends probe heartbeat messages to the server 300 on communication link 2 based on the heartbeat period 2T.
[0290] The heartbeat period 2T of communication link 2 can be determined based on the heartbeat period T on communication link 1. The time interval between time t1 and time t2 is 2T.
[0291] 5. At time t2, the electronic device 100 sends a service heartbeat message to the server 300 on communication link 1, and at the same time, sends a probe heartbeat message to the server 300 on communication link 2.
[0292] 6. After the electronic device 100 determines that the probe heartbeat message at time t2 is sent successfully, it can synchronize the heartbeat period 2T to communication link 1.
[0293] 7. The electronic device 100 may determine a new heartbeat period (2T - x) on the communication connection 1 based on the heartbeat period 2T synchronized by the communication connection 2, where x may be a preset constant.
[0294] 8. From time t2 to time t3, the electronic device 100 sends service heartbeat packets to the server 300 on the communication connection 1 based on the heartbeat period (2T - x).
[0295] 9. From time t2 to time t3, the electronic device 100 sends service heartbeat packets to the server 300 on the communication connection 2 based on the heartbeat period (4T - 2x).
[0296] The heartbeat period (4T - 2x) may be determined based on the heartbeat period 2T. The time interval between time t2 and time t3 may be (4T - 2x).
[0297] In some embodiments, the electronic device 100 may also determine the heartbeat period 4T based on the previous heartbeat period 2T of the communication connection 2. Since time t3 is the sending time of the service heartbeat packet on the communication connection 1, and the difference between time t3 and the sending time of the next probing heartbeat packet of the communication connection 2 belongs to a preset time interval (e.g., less than 60 seconds, less than 30 seconds), etc., the electronic device 100 may adjust the sending time of the next probing heartbeat packet of the communication connection 2 to time t3.
[0298] 10. At time t3, the electronic device 100 sends a service heartbeat packet to the server 300 on the communication connection 1, and at the same time, sends a probing heartbeat packet to the server 300 on the communication connection 2.
[0299] 11. At time t31, after determining that the sending of the probing heartbeat packet at time t3 fails, the electronic device 100 may 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).
[0300] Time t31 is later than time t3. The heartbeat period (3T - x) may be determined based on the heartbeat period 2T and the heartbeat period (4T - x).
[0301] 12. From time t3 to time t4, the electronic device 100 may continue to send service heartbeat packets to the server 300 on the communication connection 1 based on the heartbeat period (2T - x).
[0302] 13. At time t4, the electronic device 100 sends a probing heartbeat packet to the server 300 on the communication connection 2.
[0303] The time interval between t31 and time t4 is (3T - x).
[0304] 14. After the electronic device 100 determines that the detection heartbeat message at time t2 is successfully sent, it can synchronize the heartbeat period (3T - x) to the communication connection 1.
[0305] 15. The electronic device 100 can determine a new heartbeat period (3T - 2x) on the communication connection 1 based on the heartbeat period (3T - x) synchronized by the communication connection 2.
[0306] 16. When the electronic device 100 detects that the stop condition is met, it disconnects the communication connection 2.
[0307] 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 period (3T - 2x).
[0308] In this way, during the process of detecting the heartbeat period 2, the electronic device 100 can maintain the communication connection 1 for transmitting service data, and determine the heartbeat period 2 through detection connections such as the communication connection 2, which can not only avoid the interruption of service data but also reduce the power consumption of the electronic device 100.
[0309] Figure 8 It shows a schematic flow diagram of the execution of the service server 310 and the detection server 320 in the server 300 during the process of detecting the heartbeat period 2 provided by the embodiment of the present application.
[0310] As Figure 8 shown, during the process of detecting the heartbeat period 2, the specific execution flow of the server 300 may include the following steps:
[0311] S801. The service server 310 establishes a communication connection 1 with the electronic device 100.
[0312] In some embodiments, the specific manner in which the service server 310 establishes a communication connection 1 with the electronic device 100 and the detection server 320 establishes a communication connection 2 with the electronic device 100 may refer to the establishment manner of the TCP long connection, which will not be elaborated in detail in the present application.
[0313] S802. The service server 310 receives the service heartbeat message sent by the electronic device 100 through the communication connection 1.
[0314] Step S802 is a step that can be repeatedly executed.
[0315] As can be seen from the above embodiments, the electronic device 100 can send a service heartbeat message to the service server 310 on the communication connection 1 based on the heartbeat period of the communication connection 1 (such as the heartbeat period 1). Therefore, the service server 310 can receive the service heartbeat message periodically sent by the electronic device 100 on the communication connection 1.
[0316] In some embodiments, the service server 310 may, in response to a service heartbeat message, send a response message of the service heartbeat message to the electronic device 100 via the communication connection 1, where the response message is used to notify the electronic device 100 that the service heartbeat message has been successfully sent.
[0317] In other embodiments, the service server 310 may also receive a service data acquisition request sent by the electronic device 100 via the communication connection 1, where the service data acquisition request is used to request the service server 300 to send service data to the electronic device 100. In response to the service data acquisition request, the service server 310 may send service data to the electronic device 100 via the communication connection 1.
[0318] S803. The detection server 320 establishes a communication connection 2 with the electronic device 100 and obtains heartbeat time information sent by the electronic device 100, where the heartbeat time information is used to determine the reception time when the detection server 320 receives a detection heartbeat message next time.
[0319] In some embodiments, the heartbeat time information may include the next heartbeat period and / or the next heartbeat time. Optionally, the heartbeat time information may further include the current heartbeat time.
[0320] In some embodiments, the next heartbeat period and / or the next heartbeat time may be determined based on the current heartbeat period and a preset heartbeat period algorithm. For example, the next heartbeat period may be the sum of the current heartbeat period and a step size, or the next heartbeat period may be the product of the current heartbeat period and a constant, or the next heartbeat period may be the average of the current heartbeat period and a detection upper limit, etc. The specific calculation method may refer to the relevant descriptions in steps S502 and S503 shown above. Figure 5 and will not be elaborated here.
[0321] S804. The detection server 320 determines the reception time based on the newly received heartbeat time information.
[0322] The reception time refers to the reception time when the detection server 320 receives a detection heartbeat message next time via the communication connection 2.
[0323] In some embodiments, the heartbeat time information may include the next heartbeat period. In this case, the detection server 320 may determine the reception time based on the next heartbeat period. Exemplarily, the relationship between the next heartbeat period and the reception time satisfies the formulas (5) and (6) shown below.
[0324] Reception time = Next heartbeat time + Transmission time Formula (5)
[0325] Next heartbeat time = Next heartbeat period + Current heartbeat time Formula (6)
[0326] According to the above formulas (5) and (6), it can be known that the receiving moment can be the sum of the next heartbeat moment and the transmission moment. Among them, the transmission moment can be a preset constant, such as 20 seconds, 10 seconds, etc. The next heartbeat moment can be the sum of the current heartbeat moment and the next heartbeat period. In some embodiments, the heartbeat time information may include the current heartbeat moment. In other embodiments, the current heartbeat moment can also be determined based on the heartbeat time information carried in the previous detection heartbeat message.
[0327] Exemplarily again, the following relationship shown in formula (7) is satisfied between the next heartbeat period and the receiving moment.
[0328] Receiving moment = Previous receiving moment + Next heartbeat period Formula (7)
[0329] According to the above formulas (5) and (6), it can also be known that the receiving moment can be the sum of the previous receiving moment and the next heartbeat period. Among them, the current receiving moment refers to the moment when the heartbeat time information is received closest to the current moment.
[0330] In other embodiments, the heartbeat time information may include the next heartbeat moment. In this case, the detection server 320 can determine the receiving moment based on the next heartbeat moment through the above formula (5).
[0331] It can be understood that the embodiments here are just examples. In the embodiments of the present application, the detection server 320 can also calculate the receiving moment based on the heartbeat time information in a manner different from the above embodiments, and the present application does not make a limitation here.
[0332] S805. When the receiving moment arrives, the detection server 320 determines whether it has received a detection heartbeat message.
[0333] When the receiving moment arrives, the detection server 320 can determine whether it has received a detection heartbeat message sent by the electronic device 100 through the communication connection 2 within a preset time period. Among them, the preset time period can be the time period from when the heartbeat time information used to calculate this receiving moment is received to when the receiving moment arrives.
[0334] If the detection server 320 receives a 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.
[0335] If the detection server 320 does not receive a detection heartbeat message, it indicates that the communication connection 2 may not be maintained, then the detection server 320 can execute the following step S807.
[0336] The detection server 320 determines new heartbeat time information based on the newly received detection heartbeat message.
[0337] The detection heartbeat message may carry heartbeat time information. For the specific content of the heartbeat time information, reference may be made to the relevant description in step S803 above.
[0338] It should be noted that the heartbeat time information received each time is used to determine the receiving moment when the detection server 320 receives the detection heartbeat message next time, that is, the heartbeat time information received each time is different.
[0339] After executing step S806, the detection server 320 may execute the above step S804.
[0340] S807. The detection server 320 disconnects the communication connection 2.
[0341] After disconnecting the communication connection 2, the detection server 320 may also re - execute the above step S803.
[0342] 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, reducing the power consumption of the detection server 320.
[0343] It can be understood that Figure 8 The illustrated embodiment is only an example. In some embodiments, during the process of the detection heartbeat cycle 2, the server 300 may also execute more, fewer, or different steps from the above - mentioned embodiments. This application does not make any limitations here. In addition, if the detection server 320 is not set in the server 300, the service server 310 in the server 300 may also execute the relevant steps executed by the detection server 320 in the Figure 8 illustrated embodiment above. This application does not make any limitations here.
[0344] In some embodiments, when the detection conditions are met, the electronic device 100 may 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 may adopt different heartbeat cycle calculation methods on different detection connections, and update the detection upper limit and the detection lower limit of the detection interval based on the detection results on the multiple detection connections, so as to determine the heartbeat cycle 2.
[0345] In this way, the electronic device 100 can determine the heartbeat cycle 2 through multiple detection connections, improving the detection speed of the heartbeat cycle 2.
[0346] Next, a functional module of a communication system 10 provided by an embodiment of this application will be introduced.
[0347] Figure 9 Schematic diagram of functional modules of a communication system 10 provided by an embodiment of the present application.
[0348] As Figure 9 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 module 931 and a detection service module 932.
[0349] In the electronic device 100, the communication module 911 may establish a communication connection with other devices. For example, it may establish a communication connection 1 with the server 300 through the electronic device 200, and may also establish a communication connection 2 with the server 300 through the electronic device 200, etc. The communication module 911 may communicate with other devices. In some embodiments, the communication module 911 may send a service heartbeat message on the communication connection 1 and send a detection heartbeat message on the communication connection 2, etc. In some embodiments, the communication module 911 may also receive service data through the communication connection 1 and send the received service data to the service module 912. In other embodiments, the communication module 911 may also receive a service data acquisition request sent by the service module 912 and send the service data acquisition request to the server 300 through the communication connection 1.
[0350] The service module 912 may send a service data acquisition request to the communication module 911. 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 perform corresponding services based on the service data.
[0351] The heartbeat control module 913 may control the sending of heartbeat messages on multiple communication connections. In some embodiments, the heartbeat control module 913 may set the sending time of each heartbeat message on the communication connection 1, and may also set the sending time of each heartbeat message on the communication connection 2. When the sending time of the service heartbeat message arrives, the heartbeat control module 913 may control the communication module 911 to send the service heartbeat message through the communication connection 1. When the sending time of the detection heartbeat message arrives, the heartbeat control module 913 may control the communication module 911 to send the detection heartbeat message through the communication connection 2. In some embodiments, the heartbeat control module 913 may also align the sending times of one or more service heartbeat messages and detection heartbeat messages. The specific alignment method may refer to the relevant content in the above embodiments and will not be elaborated here.
[0352] In the electronic device 200, the intranet communication module 921 can establish communication connections (such as communication connections A1 and 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 the corresponding public network IP address. The public network communication module 923 can establish communication connections (such as communication connections B1 and B2) with the server 300 based on the translated public network IP address.
[0353] In the server 300, the service module 931 can establish a communication connection 1 with the electronic device 100 through the electronic device 200. The communication connection 1 can be used to transmit service data and can also be used to transmit service data acquisition requests. The service module 931 can receive the service data acquisition request sent by the electronic device 100 through the communication connection 1, and in response to the service data acquisition request, send service data to the electronic device 100 through the communication connection 1.
[0354] The detection service module 932 can establish a communication connection 2 with the electronic device 100 through the electronic device 200. The communication connection 2 can be used to detect the heartbeat period 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 period 2 based on the multiple communication connections. This application does not make any limitations here. The detection service module 932 can receive the 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.
[0355] It can be understood that Figure 9 The illustrated embodiments are only examples. In the embodiments of this application, the communication system 10 may further include more, fewer, or different devices than those in the above embodiments, and each electronic device (or server) may further include more, fewer, or different functional modules than those in the above embodiments. This application does not make any limitations here. In addition, in some embodiments, multiple functional modules in the above embodiments may also be integrated into one functional module, or one functional module in the above embodiments may also be divided into multiple different functional modules. This application also does not make any limitations here.
[0356] Figure 10 The figure shows a schematic flowchart of a communication method provided by an embodiment of this application.
[0357] As Figure 10 shown, the specific process of the communication method may include the following steps:
[0358] S1001. The first electronic device establishes a first connection with the server.
[0359] The first electronic device may be the electronic device 100 in the above embodiments, and the server may be the server 300 in the above embodiments. The first connection may be the communication connection 1 in the above embodiments, and the first connection is a service connection.
[0360] 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.
[0361] The first server may be the service server in the above embodiments, and the second server may be the detection server in the above embodiments. The second connection may be the communication connection 2 in the above embodiments, and the second connection is a detection connection.
[0362] In this way, different servers in the server set can provide service services and detection services respectively, and can better control the data transmission on different connections.
[0363] S1002. The first electronic device sends a first type of heartbeat message to the server based on a first period through the first connection.
[0364] The first period may be the heartbeat period 1 in the above embodiments.
[0365] The first type of heartbeat message may be the service heartbeat message in the above embodiments.
[0366] S1003. The first electronic device establishes a second connection with the server, and the second connection is used to transmit a second type of heartbeat message.
[0367] The second connection may be the communication connection 2 in the above embodiments. The second type of heartbeat message may be the detection heartbeat message in the above embodiments.
[0368] In a possible implementation, the first electronic device establishing a second connection with the server specifically includes: when it is detected that the detection condition is satisfied, 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 since 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 a second period, a detection instruction is received, and the detection instruction is used to instruct the first electronic device to determine a second period.
[0369] For other specific descriptions of the detection conditions, reference may also be made to the relevant descriptions in the above Figure 4 illustrated embodiments, which will not be elaborated here.
[0370] In this way, when the detection condition is met, a detection connection (i.e., the second connection) can be established, and the second period can be determined based on the detection connection.
[0371] In a possible implementation, the format of the heartbeat messages of the first type is the same as that of the heartbeat messages of the second type; or, the format of the heartbeat messages of the first type is different from that of the heartbeat messages of the second type.
[0372] In a possible implementation, the content in the heartbeat messages of the first type is more than that in the heartbeat messages of the second type. In this way, the transmission power consumption of the heartbeat messages of the second type can be saved.
[0373] In some embodiments, the formats of the heartbeat messages of the first type and the second type may also refer to the relevant content in the embodiments shown in Table 1 above.
[0374] S1004. The first electronic device determines the second period based on the second connection.
[0375] The second period may be the heartbeat period 2 in the above embodiments.
[0376] In a possible implementation, the second period is greater than the first period.
[0377] In this way, the transmission frequency of the heartbeat messages on the service connection can be reduced, the power consumption can be reduced, and the battery life can be improved.
[0378] In a possible implementation, the specific content of step S1004 may also refer to the relevant description in the embodiments shown above Figure 5 and will not be elaborated here.
[0379] S1005. The first electronic device sends the heartbeat messages of the first type to the server based on the second period through the first connection.
[0380] It should be noted that step S1005 and step S1006 may be executed simultaneously, or step S1005 may be executed first and then step S1006, or step S1006 may be executed first and then step S1005. The present application does not limit the execution order of step S1005 and step S1006.
[0381] S1006. The first electronic device disconnects the second connection.
[0382] In this way, service data can be transmitted on the first connection (i.e., the service connection), and the heartbeat period can be detected on the second connection (i.e., the detection connection), avoiding the interruption of service data transmission during the detection process.
[0383] In a possible implementation, the moment when the first electronic device establishes a second connection with the server is the first moment; determining the second period based on the second connection specifically includes: at the 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, the first response being a response sent by the server through the second connection in response to the first message; when it is detected that a stop condition is satisfied, determining the second period based on the time interval between the first moment and the second moment.
[0384] In a possible implementation, 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.
[0385] Exemplarily, referring to the above Figure 7 shown embodiment, the first moment may be the moment t31, and the second moment may be the moment t4. The second period may be the time interval between the moment t31 and the moment t4, or may be the difference between the time interval between the moment t31 and the moment t4 and a preset fourth constant (such as x).
[0386] In this way, when it is detected that a stop condition is satisfied, the second period can be determined based on the heartbeat period corresponding to the most recent successful heartbeat message sent on the second connection.
[0387] In a possible implementation, the time interval between the first moment and the second moment is: the product of the first period and a first constant, the first constant being a positive number greater than 1; or, the sum of the first period and a second constant, the second constant being a positive number; or, the average value of the first period and a third constant, the third constant being greater than the first period.
[0388] 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).
[0389] In this way, the next heartbeat period on the second connection can be determined based on the first period.
[0390] In a possible implementation, the method further includes: before the first moment, sending a second message to the server through the second connection, the second 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 a second connection with the server.
[0391] Exemplarily, referring to the above Figure 7 shown embodiment, the first moment may be the moment t31, and the second message may be the detection heartbeat message sent at the moment t2.
[0392] In this way, after the second connection is disconnected, the second connection can be re-established, and the second period can be determined based on the re-established second connection.
[0393] In a 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, where the third message is a heartbeat message of a second type; receiving a third response, where the third response is a response sent by the server in response to the third message through the second connection; at a fourth moment, sending a fourth message to the server through the second connection, where the fourth message is a heartbeat message of the second type, and the fourth moment is later than the third moment; receiving a fourth response, where the fourth response is a response sent by the server in response to the fourth message through the second connection; when it is detected that a stop condition is satisfied, determining the second period based on the time interval between the third moment and the fourth moment.
[0394] In a possible implementation, 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.
[0395] In this way, when it is detected that the stop condition is satisfied, the second period can be determined based on the heartbeat period corresponding to the most recent successful heartbeat message sent on the second connection.
[0396] In a possible implementation, the moment when the first electronic device establishes the 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 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.
[0397] In this way, after the second connection is disconnected, the second connection can be re-established, and the second period can be determined based on the re-established second connection.
[0398] In a 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.
[0399] In this way, the next heartbeat period of the second connection can be determined based on the current heartbeat period of the second connection.
[0400] In a possible implementation, before determining the second period based on the second connection, the method further includes: after receiving the third response, sending a first type of heartbeat message to the server based on the third period through the first connection, where the third period is the time interval between the first moment and the third moment.
[0401] In this way, during 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.
[0402] In a possible implementation, before determining the second period based on the second connection, the method further includes: after receiving the third response, sending a first type of heartbeat message to the server based on the third period through the first connection, where the third period is the difference between the time interval between the first moment and the third moment and the fourth constant.
[0403] In this way, during 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, by introducing a fixed error (i.e., the fourth constant), it is possible to avoid the heartbeat period of the first connection being equal to the timeout time.
[0404] In a possible implementation, before the third moment, the method further includes: at the fifth moment, sending a fifth message to the server through the second connection, where the fifth message is a second type of heartbeat message; receiving the fifth response, where the fifth response is the response sent by the server in response to the fifth message through the second connection; where 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.
[0405] 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 most recent successful heartbeat message sent on the second connection.
[0406] In a possible implementation, the second time interval is: the product of the third time interval and the first constant, where the first constant is a positive number greater than 1; or, the sum of the third time interval and the 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.
[0407] In this way, the next heartbeat period of the second connection can be determined based on the current heartbeat period of the second connection.
[0408] In a possible implementation, before determining the second period based on the second connection, the method further includes: after receiving the third response, sending a first type of heartbeat message to the server based on the 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 the fourth constant.
[0409] In this way, during 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. In addition, a fixed error (i.e., the fourth constant) can be introduced to avoid the heartbeat period of the first connection being equal to the timeout time.
[0410] In a possible implementation, the moment when the first electronic device establishes the second connection with the server is the first moment; determining the second period based on the second connection specifically includes: at the sixth moment, sending a sixth message to the server through the second connection, the sixth message being a second type of heartbeat message, and the sixth moment being later than the first moment; receiving the sixth response, the sixth response being the response sent by the server through the second connection in response to the sixth message; at the seventh moment, sending a seventh message to the server through the second connection, the seventh message being a second type of heartbeat message, and 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, determining the second period based on the time interval between the first moment and the sixth moment.
[0411] In a possible implementation, 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 the fourth constant.
[0412] In this way, when it is detected that the stop condition is satisfied, the second period can be determined based on the heartbeat period corresponding to the most recent successful sending of a heartbeat message on the second connection.
[0413] In a possible implementation, determining the second period based on the second connection specifically includes: at the eighth moment, sending an eighth message to the server through the second connection, the eighth message being a second type of heartbeat message; receiving the eighth response, the eighth response being the response sent by the server through the second connection in response to the eighth message; at the ninth moment, sending a ninth message to the server through the second connection, the ninth message being a second type of heartbeat message, and the ninth moment being later than the eighth moment; receiving the ninth response, the ninth response being the response sent by the server through the second connection in response to the ninth message; at the tenth moment, sending a tenth message to the server through the second connection, the tenth message being a second type of heartbeat message, and 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, determining the second period based on the time interval between the eighth moment and the ninth moment.
[0414] In a possible implementation, 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.
[0415] In this way, when it is detected that the stop condition is satisfied, the second period can be determined based on the heartbeat period corresponding to the most recent successful heartbeat packet sent on the second connection.
[0416] In a possible implementation, the stop condition includes but is not limited to any one or more of the following: the detection duration reaches the second duration, the number of times of sending heartbeat packets of the second type through the second connection reaches the first number, and the number of times of establishing the second connection reaches the second number.
[0417] Other relevant content of the stop condition can also refer to the relevant description in the above Figure 5 illustrated embodiments, which will not be elaborated here.
[0418] In a possible implementation, after the first electronic device establishes the second connection with the server, the method further includes: at the eleventh moment, sending a heartbeat packet of the first type to the server through the first connection; at the twelfth moment, sending an eleventh packet to the server through the second connection, the eleventh packet being a heartbeat packet of the second type, the twelfth moment being later than the eleventh moment, and the time interval between the eleventh moment and the twelfth moment being the fourth time interval; at the twelfth moment, sending a heartbeat packet of the first type 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.
[0419] In this way, by aligning the sending moments of the heartbeat packets on the first connection and the second connection, the number of times of waking up the first electronic device can be reduced, and the power consumption of the first electronic device can be lowered.
[0420] In a possible implementation, for the first electronic device to establish the first connection with the server, it specifically includes: the first electronic device establishes the first connection with the server through the second electronic device; for the first electronic device to establish the second connection with the server, it specifically includes: the first electronic device establishes the second connection with the server through the second electronic device.
[0421] In this way, the first electronic device can establish a communication connection with the server through the second electronic device.
[0422] In a possible implementation, the method further includes: the first electronic device establishes a third connection with the server; determining the second period based on the second connection specifically includes: determining the second period based on the second connection and the third connection.
[0423] The third connection is used to transmit heartbeat packets of the second type.
[0424] In this way, the second period can be determined based on multiple detection connections.
[0425] The various embodiments of the present application can be combined arbitrarily to achieve different technical effects.
[0426] In the above embodiments, they 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 processes or functions described in the present application are generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The computer instructions can be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center by wire (such as coaxial cable, optical fiber, digital subscriber line) or wirelessly (such as infrared, wireless, microwave, etc.). The computer-readable storage medium can be any available medium that the computer can access, or a data storage device such as a server or data center that includes one or more integrated available media. The available medium can be a magnetic medium (such as a floppy disk, hard disk, magnetic tape), an optical medium (such as a DVD), or a semiconductor medium (such as a solid-state disk (SSD)), etc.
[0427] Those of ordinary skill in the art can understand all or part of the processes in the methods of the above embodiments. These processes can be completed by relevant hardware instructed by a computer program. The program can be stored in a computer-readable storage medium. When the program is executed, it can include the processes of the above method embodiments. The foregoing storage medium includes: various media such as ROM or random access memory RAM, magnetic disk, or optical disc that can store program codes.
[0428] In summary, the above are only embodiments of the technical solutions of the present invention, and are not used to limit the protection scope of the present invention. Any modifications, equivalent replacements, improvements, 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 server is a server set, and the server includes a first server and a second server; the first server is used to establish the first connection with the first electronic device, and the second server is used to establish the second connection with the first electronic device.
3. The method according to claim 1 or 2, characterized in that: The second period is greater than the first period.
4. The method according to any one of claims 1 to 3, 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.
5. The method according to any one of claims 1 to 4, 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.
6. The method according to any one of claims 1 to 5, 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.
7. The method according to claim 6, 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.
8. The method according to any one of claims 6 to 7, 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.
9. The method according to any one of claims 1 to 5, 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.
10. The method according to claim 9, 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.
11. The method according to claim 10, 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.
12. The method according to claim 10 or 11, 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.
13. The method according to claim 10 or 11, 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.
14. The method according to claim 9, 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.
15. The method according to claim 14, 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.
16. The method according to claim 14 or 15, 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.
17. The method according to any one of claims 1 to 5, 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.
18. The method according to any one of claims 1 to 5, 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.
19. The method according to claim 18, 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.
20. The method according to any one of claims 6 to 19, 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.
21. The method according to any one of claims 1 to 20, 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.
22. The method according to any one of claims 1 to 21, 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.
23. The method according to any one of claims 1 to 5, 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.
24. An electronic device, being a first 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 first electronic device executes the method described in any one of claims 1-23.
25. A readable storage medium, comprising instructions, characterized in that: When the instructions are executed on the first electronic device, the first electronic device is caused to execute the method described in any one of claims 1 to 23.
26. A server, characterized in that: A server set includes a first server and a second server, wherein 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.