Nothing Special   »   [go: up one dir, main page]

CN111031598A - Network communication control method, device, communication equipment and storage medium - Google Patents

Network communication control method, device, communication equipment and storage medium Download PDF

Info

Publication number
CN111031598A
CN111031598A CN202010019807.5A CN202010019807A CN111031598A CN 111031598 A CN111031598 A CN 111031598A CN 202010019807 A CN202010019807 A CN 202010019807A CN 111031598 A CN111031598 A CN 111031598A
Authority
CN
China
Prior art keywords
heartbeat
network
interval
communication control
current
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202010019807.5A
Other languages
Chinese (zh)
Inventor
郑一锐
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Guangdong Oppo Mobile Telecommunications Corp Ltd
Original Assignee
Guangdong Oppo Mobile Telecommunications Corp Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Guangdong Oppo Mobile Telecommunications Corp Ltd filed Critical Guangdong Oppo Mobile Telecommunications Corp Ltd
Priority to CN202010019807.5A priority Critical patent/CN111031598A/en
Publication of CN111031598A publication Critical patent/CN111031598A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04WWIRELESS COMMUNICATION NETWORKS
    • H04W52/00Power management, e.g. TPC [Transmission Power Control], power saving or power classes
    • H04W52/02Power saving arrangements
    • H04W52/0209Power saving arrangements in terminal devices
    • H04W52/0225Power saving arrangements in terminal devices using monitoring of external events, e.g. the presence of a signal
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04WWIRELESS COMMUNICATION NETWORKS
    • H04W76/00Connection management
    • H04W76/20Manipulation of established connections
    • H04W76/25Maintenance of established connections
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D30/00Reducing energy consumption in communication networks
    • Y02D30/70Reducing energy consumption in communication networks in wireless communication networks

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Mobile Radio Communication Systems (AREA)

Abstract

The invention discloses a network communication control method, a device, communication equipment and a storage medium, wherein the method comprises the following steps: detecting the current heartbeat state of network connection between a server and a terminal application, wherein the heartbeat state at least comprises whether heartbeat is successful or not; and dynamically adjusting the network heartbeat interval according to the detected current heartbeat state of the network connection. The invention dynamically adjusts the heartbeat interval by judging whether the heartbeat is successful or not, avoids frequent disconnection of long connection due to NAT overtime, improves the network stability and reduces the consumption of flow and electric quantity. In addition, in the technical scheme of the invention, different NAT timeout times of different networks are considered, the heartbeat intervals can be distinguished aiming at different network environments, and the different network environments use respective heartbeat intervals, thereby improving the network transmission reliability.

Description

Network communication control method, device, communication equipment and storage medium
Technical Field
The present invention relates to the field of network communication technologies, and in particular, to a network communication control method, an apparatus, a communication device, and a storage medium.
Background
GCM (Google Cloud Messaging, Cloud push) is a service used to help developers send data from servers to Android applications. The GCM heartbeat interval is typically a fixed heartbeat interval, such as 15 minutes for WIFI networks and 28 minutes for data networks.
The disadvantages of such a fixed heartbeat interval are: if the heartbeat interval is short, the heartbeat is too frequent, which can cause the increase of the flow and the consumption of the electric quantity; if the heartbeat interval is long (as used by GCM), then in some network environments where NAT (network address translation) timeout is short, long connections are prone to disconnection, resulting in push delays.
Disclosure of Invention
The invention mainly aims to provide a network communication control method, a network communication control device, communication equipment and a storage medium, and aims to improve the stability of a network and reduce the consumption of flow and electric quantity.
In order to achieve the above object, the present invention provides a network communication control method, including:
detecting the current heartbeat state of network connection between a server and a terminal application, wherein the heartbeat state at least comprises whether heartbeat is successful or not;
and dynamically adjusting the network heartbeat interval according to the detected current heartbeat state of the network connection.
Optionally, the step of dynamically adjusting the network heartbeat interval according to the detected current heartbeat state of the network connection includes:
and when the current heartbeat state of the network connection is detected to be successful, increasing the network heartbeat interval.
Optionally, the step of dynamically adjusting the network heartbeat interval according to the detected current heartbeat state of the network connection includes:
and when the current heartbeat state of the network connection is detected to be heartbeat failure, reducing the network heartbeat interval.
Optionally, the step of dynamically adjusting the network heartbeat interval further includes, before the step of:
judging the type of the current network environment where the network connection is positioned;
the step of dynamically adjusting the network heartbeat interval comprises:
and dynamically adjusting the network heartbeat interval by using the adjustment interval corresponding to the current network environment according to the type of the current network environment.
Optionally, when it is detected that the current heartbeat state of the network connection is a heartbeat success, the step of increasing the network heartbeat interval includes:
when the current heartbeat state of the network connection is detected to be heartbeat success, acquiring the accumulated times of the heartbeat success;
judging whether the successfully accumulated heartbeat times reach a first preset threshold value or not;
and if the heartbeat success accumulated times reach a first preset threshold value, resetting the heartbeat success accumulated times and increasing the network heartbeat interval.
Optionally, when it is detected that the current heartbeat state of the network connection is a heartbeat failure, the step of reducing the network heartbeat interval includes:
when the current heartbeat state of the network connection is detected to be heartbeat failure, acquiring the heartbeat success accumulated times, resetting the heartbeat success accumulated times and reducing the network heartbeat interval.
Optionally, the step of reducing the network heartbeat interval further comprises, before the step of:
acquiring the accumulated times of heartbeat failure;
judging whether the accumulated heartbeat failure times reach a second preset threshold value or not;
and if the accumulated heartbeat failure times reach a second preset threshold value, clearing the accumulated heartbeat failure times, and executing the steps to reduce the network heartbeat interval.
Optionally, the step of increasing the network heartbeat interval includes:
increasing the network heartbeat interval by a preset heartbeat increase step length, wherein the preset heartbeat increase step length is determined according to preset adjustment accuracy and/or adjustment speed;
the step of reducing the network heartbeat interval comprises:
and reducing the network heartbeat interval by a preset heartbeat reduction step length, wherein the preset heartbeat reduction step length is determined according to preset adjustment accuracy and/or adjustment speed.
Optionally, the heartbeat decrease step size is not less than the heartbeat increase step size.
In addition, an embodiment of the present invention further provides a network communication control apparatus, where the network communication control apparatus includes:
the system comprises a detection module, a heartbeat module and a heartbeat module, wherein the detection module is used for detecting the current heartbeat state of network connection between a server and a terminal application, and the heartbeat state at least comprises whether heartbeat is successful or not;
and the adjusting module is used for dynamically adjusting the network heartbeat interval according to the detected current heartbeat state of the network connection.
In addition, an embodiment of the present invention further provides a communication device, where the communication device includes a memory, a processor, and a network communication control program stored in the memory and executable on the processor, and the network communication control program, when executed by the processor, implements the steps of the network communication control method described above.
Furthermore, an embodiment of the present invention further provides a computer-readable storage medium, where a network communication control program is stored, and when executed by a processor, the network communication control program implements the steps of the network communication control method described above.
According to the network communication control method, the network communication control device, the communication equipment and the storage medium provided by the embodiment of the invention, the current heartbeat state of the network connection between the server and the terminal application is detected, wherein the heartbeat state at least comprises whether the heartbeat is successful or not; and dynamically adjusting the network heartbeat interval according to the detected current heartbeat state of the network connection. Therefore, the existing method for fixing the heartbeat interval is changed, the heartbeat interval is dynamically adjusted by judging whether the heartbeat succeeds or not (for example, the heartbeat interval is increased when the heartbeat succeeds, and the heartbeat interval is reduced when the heartbeat fails), the heartbeat interval is adjusted to the most suitable length as far as possible, the long connection is prevented from being frequently disconnected due to NAT overtime, the network stability is improved, and meanwhile, the consumption of flow and electric quantity is reduced. In addition, in the technical scheme of the invention, different NAT timeout times of different networks are considered, the heartbeat intervals can be distinguished aiming at different network environments, and the different network environments use respective heartbeat intervals, thereby improving the network transmission reliability.
Drawings
Fig. 1 is a functional block diagram of a communication device to which a network communication control apparatus of the present invention belongs;
fig. 2 is a flowchart illustrating an exemplary embodiment of a network communication control method according to the present invention;
fig. 3 is a detailed flowchart of a network communication control method according to an embodiment of the present invention.
The implementation, functional features and advantages of the objects of the present invention will be further explained with reference to the accompanying drawings.
Detailed Description
It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
The main solution of the embodiment of the invention is as follows: detecting the current heartbeat state of network connection between a server and a terminal application, wherein the heartbeat state at least comprises whether heartbeat is successful or not; and dynamically adjusting the network heartbeat interval according to the detected current heartbeat state of the network connection. Therefore, the existing method for fixing the heartbeat interval is changed, the heartbeat interval is dynamically adjusted by judging whether the heartbeat succeeds or not (for example, the heartbeat interval is increased when the heartbeat succeeds, and the heartbeat interval is reduced when the heartbeat fails), the heartbeat interval is adjusted to the most suitable length as far as possible, the long connection is prevented from being frequently disconnected due to NAT overtime, the network stability is improved, and meanwhile, the consumption of flow and electric quantity is reduced. In addition, in the technical scheme of the invention, different NAT timeout times of different networks are considered, the heartbeat intervals can be distinguished aiming at different network environments, and the different network environments use respective heartbeat intervals, thereby improving the network transmission reliability.
Technical terms related to the scheme of the embodiment of the invention comprise:
network Address Translation (NAT): also known as network masking or IP masquerading, is a technique for rewriting the source IP address or destination IP address as an IP packet passes through a router or firewall. This technique is commonly used in private networks that have multiple hosts but access the internet through only one public IP address.
Heartbeat: data packets (heartbeat packets) are periodically sent between the client and the server for maintaining network connection.
Heartbeat packet (Heartbeat packet): the heartbeat packet is a self-defined command word which is used for regularly informing the self state of the other side between the client side and the server, is sent at a certain time interval, is similar to the heartbeat, and is called as the heartbeat packet.
Both receiving and sending data in the network are implemented using socks. But if the socket is disconnected, there must be a problem when sending and receiving data. How to determine if this socket is still available requires the creation of a heartbeat mechanism in the system.
Taking the heartbeat mechanism implemented by TCP as an example, if the heartbeat is set, the TCP will send a set number of heartbeats (for example, 2 heartbeats) within a certain time (for example, set to be 3 seconds), and this information will not affect the protocol defined by itself. The heartbeat is to send a self-defined structure (heartbeat packet or heartbeat frame) at regular time to let the other party know that the other party is online so as to ensure the validity of the link.
Therefore, the heartbeat packet is a simple message sent between the client and the server to the other side at regular time, so that the other side knows that the other side is on line. Taking the server as an example, if the server does not receive the client information within several minutes, the client is disconnected. The heartbeat packet is called as the heartbeat packet because: it is sent at regular intervals like a heartbeat to maintain a long connection between the client and the server, and as to the content of this packet, there is no particular provision, and it is generally a very small packet or an empty packet containing only a header. For example, a timer is set, the server sends a null packet to the client at a certain time interval, then the client feeds back the same null packet, and if the server cannot receive the feedback packet sent by the client within a certain time interval, the server determines that the connection is dropped. However, under long connections, there may be no data to go for a long period of time. At this time, a heartbeat packet is needed to maintain a long connection, keep alive. In general, heartbeat packets are mainly used for keep-alive and disconnection processing of long connections. In general application, the decision time is 30-40 seconds, and if higher is required, it can be set at 6-9 seconds.
The embodiment of the invention considers that in the related technology, when the server side pushes the message to the terminal application, a fixed heartbeat interval is usually adopted to monitor the network connection state. The disadvantage of the fixed heartbeat interval is that: if the heartbeat interval is short, the heartbeat is too frequent, which can cause the increase of the flow and the consumption of the electric quantity; if the heartbeat interval is long (as used by GCM), then in some network environments where NAT (network address translation) timeout is short, long connections are prone to disconnection, resulting in push delays.
Based on this, the embodiment of the present invention provides a solution, which can adjust the heartbeat interval to an appropriate length as much as possible, so as to avoid frequent disconnection of long connection due to NAT timeout, thereby improving network stability, and reducing consumption of traffic and electric quantity.
Specifically, referring to fig. 1, fig. 1 is a functional module schematic diagram of a communication device to which the network communication control apparatus of the present invention belongs. The network communication control device may be a device which is independent of the communication device, can realize network communication, and can perform data processing, and it may be carried on the communication device in the form of hardware or software. The communication equipment can be an intelligent mobile terminal such as a mobile phone and a tablet personal computer, and can also be a fixed terminal, a server and the like.
In this embodiment, the communication device to which the network communication control apparatus belongs at least includes an output module 110, a processor 120, a memory 130 and a communication module 140.
The memory 130 stores an operating system and a network communication control program, and the network communication control device may store information such as a current heartbeat state of a detected network connection between the server and the terminal application in the memory 130; the output module 110 may be a display screen, a speaker, etc. The communication module 140 may include a WIFI module, a mobile communication module, a bluetooth module, and the like, and communicates with an external device or a server through the communication module 140.
Wherein the network communication control program in the memory 130 when executed by the processor implements the steps of:
detecting the current heartbeat state of network connection between a server and a terminal application, wherein the heartbeat state at least comprises whether heartbeat is successful or not;
and dynamically adjusting the network heartbeat interval according to the detected current heartbeat state of the network connection.
Further, the network communication control program in the memory 130 when executed by the processor further implements the steps of:
and when the current heartbeat state of the network connection is detected to be successful, increasing the network heartbeat interval.
And when the current heartbeat state of the network connection is detected to be heartbeat failure, reducing the network heartbeat interval.
Further, the network communication control program in the memory 130 when executed by the processor further implements the steps of:
judging the type of the current network environment where the network connection is positioned;
and dynamically adjusting the network heartbeat interval by using the adjustment interval corresponding to the current network environment according to the type of the current network environment.
Further, the network communication control program in the memory 130 when executed by the processor further implements the steps of:
when the current heartbeat state of the network connection is detected to be heartbeat success, acquiring the accumulated times of the heartbeat success;
judging whether the successfully accumulated heartbeat times reach a first preset threshold value or not;
and if the heartbeat success accumulated times reach a first preset threshold value, resetting the heartbeat success accumulated times and increasing the network heartbeat interval.
Further, the network communication control program in the memory 130 when executed by the processor further implements the steps of:
when the current heartbeat state of the network connection is detected to be heartbeat failure, acquiring the heartbeat success accumulated times, resetting the heartbeat success accumulated times and reducing the network heartbeat interval.
Further, the network communication control program in the memory 130 when executed by the processor further implements the steps of:
acquiring the accumulated times of heartbeat failure;
judging whether the accumulated heartbeat failure times reach a second preset threshold value or not;
and if the accumulated heartbeat failure times reach a second preset threshold value, clearing the accumulated heartbeat failure times, and executing the steps to reduce the network heartbeat interval.
Further, the network communication control program in the memory 130 when executed by the processor further implements the steps of:
increasing the network heartbeat interval by a preset heartbeat increase step length, wherein the preset heartbeat increase step length is determined according to preset adjustment accuracy and/or adjustment speed;
and reducing the network heartbeat interval by a preset heartbeat reduction step length, wherein the preset heartbeat reduction step length is determined according to preset adjustment accuracy and/or adjustment speed.
According to the scheme, the current heartbeat state of the network connection between the server and the terminal application is detected, wherein the heartbeat state at least comprises whether the heartbeat is successful or not; and dynamically adjusting the network heartbeat interval according to the detected current heartbeat state of the network connection. Therefore, the existing method for fixing the heartbeat interval is changed, the heartbeat interval is dynamically adjusted by judging whether the heartbeat succeeds or not (for example, the heartbeat interval is increased when the heartbeat succeeds, and the heartbeat interval is reduced when the heartbeat fails), the heartbeat interval is adjusted to the most suitable length as far as possible, the long connection is prevented from being frequently disconnected due to NAT overtime, the network stability is improved, and meanwhile, the consumption of flow and electric quantity is reduced. In addition, in the technical scheme of the invention, different NAT timeout times of different networks are considered, the heartbeat intervals can be distinguished aiming at different network environments, and the different network environments use respective heartbeat intervals, thereby improving the network transmission reliability.
The method embodiment of the present invention is proposed based on the above communication device architecture but not limited to the above architecture.
Referring to fig. 2, fig. 2 is a flowchart illustrating a network communication control method according to an exemplary embodiment of the present invention.
The network communication control method comprises the following steps:
step S101, detecting the current heartbeat state of network connection between a server and a terminal application, wherein the heartbeat state at least comprises whether heartbeat is successful or not;
the execution subject of the embodiment of the method can be a network communication control device, and can also be a server or other communication equipment. The network communication control means may be provided on the above-mentioned server or other communication device.
The scheme of the embodiment can be applied to a service scene that a server sends data to a terminal application (such as an Android application program), in the scene, the network connection state between the server and the terminal application is monitored through heartbeat state detection, the heartbeat interval is dynamically adjusted by judging whether the heartbeat succeeds or not (such as increasing the heartbeat interval when the heartbeat succeeds and reducing the heartbeat interval when the heartbeat fails), the heartbeat interval is adjusted to the optimum length as much as possible, frequent disconnection of long connection due to NAT overtime is avoided, the network stability is improved, and meanwhile, consumption of flow and electric quantity can be reduced.
Specifically, in order to monitor the network connection state between the server and the terminal application, so that the server can accurately push data to the terminal application, the server sends a heartbeat packet (or a heartbeat message or a heartbeat packet) to the terminal at a certain interval (i.e., a heartbeat interval in this embodiment) to perform heartbeat state detection. The heartbeat state may include whether the heartbeat is successful or not, that is, the heartbeat is successful or failed, the heartbeat success refers to success of sending the heartbeat packet to the terminal by the server, and the heartbeat failure refers to failure of sending the heartbeat packet to the terminal by the server, where the failure may be due to unstable network state, a drop of the terminal side, or no feedback of the heartbeat packet from the terminal side within a preset time.
And step S102, dynamically adjusting the network heartbeat interval according to the detected current heartbeat state of the network connection.
The server side detects the current heartbeat state of the network connection between the server and the terminal application, and dynamically adjusts the network heartbeat interval according to whether the detected current heartbeat state of the network connection is successful or not.
The network heartbeat interval refers to a time interval of sending a heartbeat packet to the terminal side by the server. In this embodiment, the network heartbeat interval is not a fixed time interval, but can be dynamically adjusted according to actual conditions, and the heartbeat interval is adjusted to an optimum length as much as possible, so that frequent disconnection of a long connection due to NAT timeout is avoided, network stability is improved, and consumption of traffic and electric quantity can be reduced.
According to the scheme, the current heartbeat state of the network connection between the server and the terminal application is detected, wherein the heartbeat state at least comprises whether the heartbeat is successful or not; and dynamically adjusting the network heartbeat interval according to the detected current heartbeat state of the network connection. Therefore, the existing method for fixing the heartbeat interval is changed, the heartbeat interval is dynamically adjusted by judging whether the heartbeat succeeds or not (for example, the heartbeat interval is increased when the heartbeat succeeds, and the heartbeat interval is reduced when the heartbeat fails), the heartbeat interval is adjusted to the most suitable length as far as possible, the long connection is prevented from being frequently disconnected due to NAT overtime, the network stability is improved, and meanwhile, the consumption of flow and electric quantity is reduced.
More specifically, as an embodiment, when dynamically adjusting the network heartbeat interval according to the detected current heartbeat state of the network connection, the following scheme may be adopted:
and when the current heartbeat state of the network connection is detected to be successful, increasing the network heartbeat interval.
And when the current heartbeat state of the network connection is detected to be heartbeat failure, reducing the network heartbeat interval.
The heartbeat interval is adjusted according to the success or failure of the heartbeat, the heartbeat interval is increased when the heartbeat is successful, and the heartbeat interval is decreased when the heartbeat is failed.
Wherein, the specific rules of increasing the heartbeat interval and decreasing the heartbeat interval can be set according to the actual conditions.
During specific implementation, the network heartbeat interval can be increased by a preset heartbeat increasing step length, wherein the preset heartbeat increasing step length is determined according to preset adjustment accuracy and/or adjustment speed;
similarly, the network heartbeat interval may be decreased by a preset heartbeat decrease step size, which is determined according to a preset adjustment accuracy and/or adjustment speed.
Wherein, as an embodiment, the heartbeat decreasing step size is not smaller than the heartbeat increasing step size.
Examples are as follows:
when the heartbeat is successful, the heartbeat interval is increased by a preset heartbeat increasing step length, wherein the heartbeat increasing step length is determined according to the requirements of the adjustment accuracy and the adjustment speed, and the value can be 1 minute in a specific example.
When the heartbeat fails, the heartbeat interval is reduced by a preset heartbeat reduction step length, wherein the heartbeat reduction step length is also determined according to the adjustment accuracy and the adjustment speed, and is preferably not less than the heartbeat increase step length, so that the heartbeat interval can return to the NAT timeout time after being reduced once after being increased to exceed the NAT timeout time, and the value can be taken as 1 minute in a specific example.
Further, as another embodiment, when dynamically adjusting the network heartbeat interval according to the detected current heartbeat state of the network connection, the following scheme may also be adopted:
after detecting the current heartbeat state of the network connection between the server and the terminal application, judging the type of the current network environment in which the network connection is positioned;
and dynamically adjusting the network heartbeat interval by using the adjustment interval corresponding to the current network environment according to the type of the current network environment.
In the present embodiment, it is considered that: since the NAT timeout times of different networks are different, the optimal heartbeat interval adjusted in one network is likely to be inappropriate in another network, and thus the heartbeat interval needs to be used in a network environment different from that of the other network. I.e. different networks configure different heartbeat intervals, different networks use respective heartbeat intervals.
As an application scene, a network environment can be divided into a WIFI network and a data network, corresponding network heartbeat intervals are configured according to different characteristics of the WIFI network and the data network respectively, so that the heartbeat intervals are adjusted to be the most suitable length as far as possible according to the network environment, long connection is avoided being frequently disconnected due to NAT overtime, network stability is improved, and consumption of flow and electric quantity is reduced.
Further, in combination with the above embodiments, when it is detected that the current heartbeat state of the network connection is a heartbeat success, a specific processing scheme for increasing the network heartbeat interval may be as follows:
when the current heartbeat state of the network connection is detected to be heartbeat success, acquiring the accumulated times of the heartbeat success;
judging whether the accumulated number of successful heartbeats reaches a first preset threshold value, wherein the first preset threshold value can be set according to actual conditions; the accumulated number of successful heartbeats can be counted by a timer.
And if the heartbeat success accumulated times reach a first preset threshold value, resetting the heartbeat success accumulated times and increasing the network heartbeat interval.
The heartbeat success frequency threshold value has the function of considering the complexity of the network environment and ensuring that the heartbeat interval is increased when the network environment is stable, namely the heartbeat interval is increased after the success of multiple heartbeats is detected so as to reduce errors caused by the instability of the network environment.
In addition, the heartbeat success frequency threshold, that is, the value of the first preset threshold, is set according to the actual situation, and the increase speed of the heartbeat interval is slower if the value is too large, which may be 5 in a specific example.
And when the successful accumulated times of the heartbeats reach a first preset threshold, increasing the network heartbeat interval, and simultaneously resetting the successful accumulated times of the heartbeats to be convenient for counting the successful times of the heartbeats again in the following, and judging whether to increase the network heartbeat interval or not based on the set successful times threshold of the heartbeats.
In addition, in order to control the heartbeat interval not to increase without limit, an upper limit value of the network heartbeat interval can be set. This is because: after the network heartbeat interval is increased for multiple times, the value of the network heartbeat interval is continuously increased, however, considering the stability of network connection, the network heartbeat interval cannot be increased without limit, so the upper limit value of the network heartbeat interval can be set, and the network heartbeat interval is allowed to be increased before the upper limit value is reached.
Further, in combination with the foregoing embodiments, when it is detected that the current heartbeat state of the network connection is a heartbeat failure, the processing scheme for reducing the network heartbeat interval may be as follows:
when the current heartbeat state of the network connection is detected to be heartbeat failure, acquiring the heartbeat success accumulated times, resetting the heartbeat success accumulated times and reducing the network heartbeat interval.
The clearing of the accumulated heartbeat success times is to consider that the current heartbeat fails, at this time, the network heartbeat interval needs to be reduced, and the execution condition of the increase of the network heartbeat interval needs to be judged again, so that the network heartbeat success times need to be counted again, and the error caused by the increase of the network heartbeat interval is avoided.
The flow of the refinement of the present embodiment can be seen with reference to fig. 3.
Further, in the above scheme, before reducing the network heartbeat interval, the following scheme may also be adopted:
acquiring the accumulated times of heartbeat failure;
judging whether the accumulated heartbeat failure times reach a second preset threshold value or not;
and if the accumulated heartbeat failure times reach a second preset threshold value, clearing the accumulated heartbeat failure times, and executing the steps to reduce the network heartbeat interval.
The heartbeat failure frequency threshold value is set to be a second preset threshold value, and the heartbeat failure frequency threshold value plays a role in eliminating the conditions of accidental failure, unstable networks such as subway places and the like. The value is set according to the actual situation, and the condition of continuous heartbeat failure is increased due to overlarge value, so that the value can be 3 in a specific example.
According to the scheme, the current heartbeat state of the network connection between the server and the terminal application is detected, wherein the heartbeat state at least comprises whether the heartbeat is successful or not; and dynamically adjusting the network heartbeat interval according to the detected current heartbeat state of the network connection. Therefore, the existing method for fixing the heartbeat interval is changed, the heartbeat interval is dynamically adjusted by judging whether the heartbeat succeeds or not (for example, the heartbeat interval is increased when the heartbeat succeeds, and the heartbeat interval is reduced when the heartbeat fails), the heartbeat interval is adjusted to the most suitable length as far as possible, the long connection is prevented from being frequently disconnected due to NAT overtime, the network stability is improved, and meanwhile, the consumption of flow and electric quantity is reduced. In addition, in the technical scheme of the invention, different NAT timeout times of different networks are considered, the heartbeat intervals can be distinguished aiming at different network environments, and the different network environments use respective heartbeat intervals, thereby improving the network transmission reliability.
The scheme of adjusting the heartbeat interval between the server and the client on the terminal through heartbeat state detection is elaborated in detail through specific application scenes.
Generally, after a client is connected to a server, in order to ensure that the authenticity of the connection state is known, or in order to prevent some networks from being automatically disconnected when no data is transmitted for a long time, the server also sends a piece of data regularly, the heartbeat is adopted to monitor the network connection state, the heartbeat detection is used to ensure the network connection state, and when the heartbeat has a problem, the protocol state is timely switched to sense the network change.
The principle of the heartbeat detection technology is as follows: the packet sending interval is determined by a timer, and heartbeat packets (heartbeat messages) are sent periodically according to the timer. And determining the overtime duration of detection according to the protocol characteristics, namely determining that the state changes if no heartbeat detection message is received within the overtime duration. The detection is simply completed by using the heartbeat message according to the packet sending interval and the packet sending times.
In practical application, different protocols and applications have different requirements on time, so that packet sending intervals and times of heartbeat detection used by different protocols are different, some protocol heartbeat intervals reach millisecond level, some protocol heartbeat intervals have minute level, some protocol heartbeats continuously send three messages to be considered as timeout, and some protocol heartbeats continuously send dozens of messages to be considered as timeout. Many times, the packet sending interval and the packet sending times can be manually adjusted, a numerical value suitable for the network is configured according to the actual network condition, at this time, abundant network experience is often needed, parameters are properly set, and the method is very critical to the network stability.
Such as: in a complex network environment, the Hello heartbeat of the OSPF is set to be sent once every 1 second, and the 3-second overtime is not a proper parameter, so that the OSPF vibrates when the network slightly fluctuates, the OSPF vibrates to cause the vibration of the route and influence the service, and the heartbeat time of the OSPF can be properly prolonged at the moment, so that the OSPF protocol stability is improved. In addition, the accuracy of the timer used for heartbeat detection also affects the accuracy of detection, a software timer is adopted in general network equipment, the timer is calculated by the clock master frequency in the equipment, the time accuracy is wrong, the time deviation of the operation of the general network equipment for one year can reach more than ten hours, so that the timer depending on the clock has errors, the judgment of heartbeat overtime is affected, and the factor is also considered when the heartbeat detection overtime time is set, so that the misjudgment of heartbeat monitoring is avoided. The heartbeat detection needs time when the abnormality is found until the state changes, and although the time can be set, if the time is set to be too short, misjudgment is easily caused. Moreover, even if the time is shorter, the network is actually abnormal, for example, the STP heartbeat detection finds that the loop is eliminated, the blocked port needs to be opened, which requires a timeout time during which the network service is affected, so the network service is affected during the time during which the heartbeat detection timeout time is not yet reached, so the heartbeat detection is a lossy technique, and the magnitude of the effect is related to the timeout setting.
Based on the heartbeat detection principle, in the scheme of the embodiment, the current heartbeat state of the network connection between the server and the terminal application is detected, wherein the heartbeat state at least comprises whether the heartbeat is successful or not; and dynamically adjusting the network heartbeat interval according to the detected current heartbeat state of the network connection. Therefore, the existing method for fixing the heartbeat interval is changed, the heartbeat interval is dynamically adjusted by judging whether the heartbeat succeeds or not (for example, the heartbeat interval is increased when the heartbeat succeeds, and the heartbeat interval is reduced when the heartbeat fails), the heartbeat interval is adjusted to the most suitable length as far as possible, the long connection is prevented from being frequently disconnected due to NAT overtime, the network stability is improved, and meanwhile, the consumption of flow and electric quantity is reduced. In addition, in the technical scheme of the invention, different NAT timeout times of different networks are considered, the heartbeat intervals can be distinguished aiming at different network environments, and the different network environments use respective heartbeat intervals, thereby improving the network transmission reliability.
In addition, an embodiment of the present invention further provides a network communication control apparatus, where the network communication control apparatus includes:
the system comprises a detection module, a heartbeat module and a heartbeat module, wherein the detection module is used for detecting the current heartbeat state of network connection between a server and a terminal application, and the heartbeat state at least comprises whether heartbeat is successful or not;
and the adjusting module is used for dynamically adjusting the network heartbeat interval according to the detected current heartbeat state of the network connection.
For the principle and implementation process of implementing network communication control in this embodiment, please refer to the above embodiments, which are not described herein again.
In addition, an embodiment of the present invention further provides a communication device, where the communication device includes a memory, a processor, and a network communication control program stored in the memory and executable on the processor, and the network communication control program, when executed by the processor, implements the steps of the network communication control method according to the above embodiment.
Since the network communication control program is executed by the processor, all technical solutions of all the foregoing embodiments are adopted, so that at least all the beneficial effects brought by all the technical solutions of all the foregoing embodiments are achieved, and details are not repeated herein.
Furthermore, an embodiment of the present invention further provides a computer-readable storage medium, where a network communication control program is stored on the computer-readable storage medium, and when executed by a processor, the network communication control program implements the steps of the network communication control method according to the above embodiment.
Since the network communication control program is executed by the processor, all technical solutions of all the foregoing embodiments are adopted, so that at least all the beneficial effects brought by all the technical solutions of all the foregoing embodiments are achieved, and details are not repeated herein.
Compared with the prior art, the network communication control method, the network communication control device, the network communication control communication equipment and the network communication control storage medium provided by the embodiment of the invention detect the current heartbeat state of the network connection between the server and the terminal application, wherein the heartbeat state at least comprises whether the heartbeat is successful or not; and dynamically adjusting the network heartbeat interval according to the detected current heartbeat state of the network connection. Therefore, the existing method for fixing the heartbeat interval is changed, the heartbeat interval is dynamically adjusted by judging whether the heartbeat succeeds or not (for example, the heartbeat interval is increased when the heartbeat succeeds, and the heartbeat interval is reduced when the heartbeat fails), the heartbeat interval is adjusted to the most suitable length as far as possible, the long connection is prevented from being frequently disconnected due to NAT overtime, the network stability is improved, and meanwhile, the consumption of flow and electric quantity is reduced. In addition, in the technical scheme of the invention, different NAT timeout times of different networks are considered, the heartbeat intervals can be distinguished aiming at different network environments, and the different network environments use respective heartbeat intervals, thereby improving the network transmission reliability.
It should be noted that, in this document, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or system that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or system. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other like elements in a process, method, article, or system that comprises the element.
The above-mentioned serial numbers of the embodiments of the present invention are merely for description and do not represent the merits of the embodiments.
Through the above description of the embodiments, those skilled in the art will clearly understand that the method of the above embodiments can be implemented by software plus a necessary general hardware platform, and certainly can also be implemented by hardware, but in many cases, the former is a better implementation manner. Based on such understanding, the technical solution of the present invention may be embodied in the form of a software product, which is stored in a storage medium (e.g., ROM/RAM, magnetic disk, optical disk) and includes instructions for enabling a terminal device (e.g., a mobile phone, a computer, a server, a controlled terminal, or a network device) to execute the method of each embodiment of the present invention.
The above description is only a preferred embodiment of the present invention, and not intended to limit the scope of the present invention, and all modifications of equivalent structures and equivalent processes, which are made by using the contents of the present specification and the accompanying drawings, or directly or indirectly applied to other related technical fields, are included in the scope of the present invention.

Claims (12)

1. A network communication control method, comprising:
detecting the current heartbeat state of network connection between a server and a terminal application, wherein the heartbeat state at least comprises whether heartbeat is successful or not;
and dynamically adjusting the network heartbeat interval according to the detected current heartbeat state of the network connection.
2. The network communication control method of claim 1, wherein the step of dynamically adjusting the network heartbeat interval based on the detected current heartbeat status of the network connection comprises:
and when the current heartbeat state of the network connection is detected to be successful, increasing the network heartbeat interval.
3. The network communication control method of claim 2, wherein the step of dynamically adjusting the network heartbeat interval based on the detected current heartbeat status of the network connection comprises:
and when the current heartbeat state of the network connection is detected to be heartbeat failure, reducing the network heartbeat interval.
4. The network communication control method of claim 1, wherein the step of dynamically adjusting the network heartbeat interval is preceded by the step of:
judging the type of the current network environment where the network connection is positioned;
the step of dynamically adjusting the network heartbeat interval comprises:
and dynamically adjusting the network heartbeat interval by using the adjustment interval corresponding to the current network environment according to the type of the current network environment.
5. The network communication control method according to claim 2, wherein the step of increasing the network heartbeat interval when detecting that the current heartbeat status of the network connection is heartbeat success comprises:
when the current heartbeat state of the network connection is detected to be heartbeat success, acquiring the accumulated times of the heartbeat success;
judging whether the successfully accumulated heartbeat times reach a first preset threshold value or not;
and if the heartbeat success accumulated times reach a first preset threshold value, resetting the heartbeat success accumulated times and increasing the network heartbeat interval.
6. The network communication control method according to claim 3, wherein the step of reducing the network heartbeat interval when detecting that the current heartbeat status of the network connection is a heartbeat failure comprises:
when the current heartbeat state of the network connection is detected to be heartbeat failure, acquiring the heartbeat success accumulated times, resetting the heartbeat success accumulated times and reducing the network heartbeat interval.
7. The network communication control method of claim 6, wherein the step of reducing the network heartbeat interval is preceded by the step of:
acquiring the accumulated times of heartbeat failure;
judging whether the accumulated heartbeat failure times reach a second preset threshold value or not;
and if the accumulated heartbeat failure times reach a second preset threshold value, clearing the accumulated heartbeat failure times, and executing the steps to reduce the network heartbeat interval.
8. The network communication control method according to claim 3,
the step of increasing the network heartbeat interval comprises:
increasing the network heartbeat interval by a preset heartbeat increase step length, wherein the preset heartbeat increase step length is determined according to preset adjustment accuracy and/or adjustment speed;
the step of reducing the network heartbeat interval comprises:
and reducing the network heartbeat interval by a preset heartbeat reduction step length, wherein the preset heartbeat reduction step length is determined according to preset adjustment accuracy and/or adjustment speed.
9. The network communication control method according to claim 8, wherein the heartbeat decrease step size is not smaller than the heartbeat increase step size.
10. A network communication control apparatus, characterized in that the network communication control apparatus comprises:
the system comprises a detection module, a heartbeat module and a heartbeat module, wherein the detection module is used for detecting the current heartbeat state of network connection between a server and a terminal application, and the heartbeat state at least comprises whether heartbeat is successful or not;
and the adjusting module is used for dynamically adjusting the network heartbeat interval according to the detected current heartbeat state of the network connection.
11. A communication device comprising a memory, a processor, and a network communication control program stored on the memory and executable on the processor, the network communication control program when executed by the processor implementing the steps of the network communication control method according to any one of claims 1-9.
12. A computer-readable storage medium, characterized in that the computer-readable storage medium has stored thereon a network communication control program that, when executed by a processor, implements the steps of the network communication control method according to any one of claims 1 to 9.
CN202010019807.5A 2020-01-08 2020-01-08 Network communication control method, device, communication equipment and storage medium Pending CN111031598A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010019807.5A CN111031598A (en) 2020-01-08 2020-01-08 Network communication control method, device, communication equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010019807.5A CN111031598A (en) 2020-01-08 2020-01-08 Network communication control method, device, communication equipment and storage medium

Publications (1)

Publication Number Publication Date
CN111031598A true CN111031598A (en) 2020-04-17

Family

ID=70202566

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010019807.5A Pending CN111031598A (en) 2020-01-08 2020-01-08 Network communication control method, device, communication equipment and storage medium

Country Status (1)

Country Link
CN (1) CN111031598A (en)

Cited By (11)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112511368A (en) * 2020-10-16 2021-03-16 深圳市科漫达智能管理科技有限公司 Service heartbeat monitoring method and related device
CN112512103A (en) * 2020-11-02 2021-03-16 鹏城实验室 Power-saving accurate mobile terminal network measurement method
CN113452576A (en) * 2021-06-24 2021-09-28 青岛海尔科技有限公司 Network environment monitoring method and device, storage medium and electronic device
CN113472882A (en) * 2021-06-30 2021-10-01 北京百度网讯科技有限公司 Network state switching method and device, client device and storage medium
CN113890894A (en) * 2021-10-19 2022-01-04 平安普惠企业管理有限公司 Keep-alive method and device for client communication link, electronic equipment and storage medium
US11290866B2 (en) 2020-08-14 2022-03-29 Samsung Electronics Co., Ltd. Real-time lightweight NAT keep-alive interval optimization for multi-SIM mobile devices
CN114268565A (en) * 2021-12-22 2022-04-01 深圳优美创新科技有限公司 Terminal device, heartbeat packet transmission interval detection method thereof and storage medium
CN114915569A (en) * 2022-05-06 2022-08-16 杭州小电科技股份有限公司 Intelligent heartbeat control method and device, electronic device and storage medium
CN115190160A (en) * 2022-05-25 2022-10-14 杭州脸脸会网络技术有限公司 Screen-off monitoring method and device for screen equipment, electronic device and storage medium
CN115278804A (en) * 2022-06-25 2022-11-01 荣耀终端有限公司 Network selection method and related equipment
CN117294750A (en) * 2023-11-27 2023-12-26 杭州涂鸦信息技术有限公司 Method and device for adjusting MQTT heartbeat frequency

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105577507A (en) * 2014-11-10 2016-05-11 中国移动通信集团广东有限公司 Heartbeat packet transmission interval adjustment method, device and server
CN105610913A (en) * 2015-12-22 2016-05-25 用友网络科技股份有限公司 Heartbeat keep-alive method and apparatus for long connection in communication network
US20160308748A1 (en) * 2014-06-26 2016-10-20 Tencent Technology (Shenzhen) Company Limited Method and system for heartbeat adaptation
US20170118709A1 (en) * 2014-06-18 2017-04-27 Huawei Technologies Co., Ltd. Heartbeat adjustment method, apparatus, and terminal
CN107645529A (en) * 2016-07-21 2018-01-30 腾讯科技(深圳)有限公司 Heartbeat packet transmission method and device

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20170118709A1 (en) * 2014-06-18 2017-04-27 Huawei Technologies Co., Ltd. Heartbeat adjustment method, apparatus, and terminal
US20160308748A1 (en) * 2014-06-26 2016-10-20 Tencent Technology (Shenzhen) Company Limited Method and system for heartbeat adaptation
CN105577507A (en) * 2014-11-10 2016-05-11 中国移动通信集团广东有限公司 Heartbeat packet transmission interval adjustment method, device and server
CN105610913A (en) * 2015-12-22 2016-05-25 用友网络科技股份有限公司 Heartbeat keep-alive method and apparatus for long connection in communication network
CN107645529A (en) * 2016-07-21 2018-01-30 腾讯科技(深圳)有限公司 Heartbeat packet transmission method and device

Cited By (15)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US11290866B2 (en) 2020-08-14 2022-03-29 Samsung Electronics Co., Ltd. Real-time lightweight NAT keep-alive interval optimization for multi-SIM mobile devices
CN112511368A (en) * 2020-10-16 2021-03-16 深圳市科漫达智能管理科技有限公司 Service heartbeat monitoring method and related device
CN112512103B (en) * 2020-11-02 2023-08-18 鹏城实验室 Power-saving accurate mobile terminal network measurement method
CN112512103A (en) * 2020-11-02 2021-03-16 鹏城实验室 Power-saving accurate mobile terminal network measurement method
CN113452576A (en) * 2021-06-24 2021-09-28 青岛海尔科技有限公司 Network environment monitoring method and device, storage medium and electronic device
CN113472882A (en) * 2021-06-30 2021-10-01 北京百度网讯科技有限公司 Network state switching method and device, client device and storage medium
CN113890894A (en) * 2021-10-19 2022-01-04 平安普惠企业管理有限公司 Keep-alive method and device for client communication link, electronic equipment and storage medium
CN113890894B (en) * 2021-10-19 2024-03-01 广东迅维信息产业股份有限公司 Client communication link keep-alive method and device, electronic equipment and storage medium
CN114268565A (en) * 2021-12-22 2022-04-01 深圳优美创新科技有限公司 Terminal device, heartbeat packet transmission interval detection method thereof and storage medium
CN114915569A (en) * 2022-05-06 2022-08-16 杭州小电科技股份有限公司 Intelligent heartbeat control method and device, electronic device and storage medium
CN114915569B (en) * 2022-05-06 2024-06-04 杭州小电科技股份有限公司 Heartbeat intelligent control method, device, electronic device and storage medium
CN115190160A (en) * 2022-05-25 2022-10-14 杭州脸脸会网络技术有限公司 Screen-off monitoring method and device for screen equipment, electronic device and storage medium
CN115278804A (en) * 2022-06-25 2022-11-01 荣耀终端有限公司 Network selection method and related equipment
CN117294750A (en) * 2023-11-27 2023-12-26 杭州涂鸦信息技术有限公司 Method and device for adjusting MQTT heartbeat frequency
CN117294750B (en) * 2023-11-27 2024-03-01 杭州涂鸦信息技术有限公司 Method and device for adjusting MQTT heartbeat frequency

Similar Documents

Publication Publication Date Title
CN111031598A (en) Network communication control method, device, communication equipment and storage medium
US10462707B2 (en) Data transmission method and apparatus
CN107070689B (en) Method and apparatus for reducing false alarms when using network keep-alive messages
JP4509545B2 (en) Reliable messaging system with configurable settings
EP2425592B1 (en) Adaptive rate control based on overload signals
EP3226481B1 (en) Method for heartbeat packet processing by using proxy, apparatus, and communications system
KR20060051716A (en) Scheduled determination of network resource availability
US10516599B1 (en) Link priority for loop-protect
CN113300816B (en) Node positioning method, network transmission method, device and equipment
CN108123848B (en) Equipment monitoring method and device
WO2017190467A1 (en) Adjustment method and apparatus for maximum transmission unit of terminal, and terminal device
CN109962827B (en) Equipment link detection method, device, equipment and readable storage medium
CN108933818B (en) Communication method and device
CN109600436B (en) Distributed iscsi service implementation method, system and related device
CA2732434C (en) Controlling data flow through a data communications link
EP4262156A1 (en) Method for detecting state of bgp session, apparatus and network devices
CN111414262B (en) Service calling method and device
EP3628117B1 (en) A method of providing management and control of hotspots with reduced messaging
CN112787970A (en) Method and apparatus for subscribing to event streams
CN114205405B (en) BFD message sending method and device, electronic equipment and storage medium
WO2021164370A1 (en) Method and apparatus for switching length of bidirectional forwarding detection packet, and storage medium
US20240305552A1 (en) Managing active and standby gateways using duplicate address detection packets
CN116032853A (en) Flow control method, device, electronic equipment and storage medium
CN114826888A (en) Message sending method, device, equipment and storage medium
CN116346767A (en) Communication method, electronic equipment and communication system

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
RJ01 Rejection of invention patent application after publication
RJ01 Rejection of invention patent application after publication

Application publication date: 20200417