CN112422646B - Method, device and storage medium for realizing UDP dynamic heartbeat - Google Patents

Method, device and storage medium for realizing UDP dynamic heartbeat Download PDF

Info

Publication number
CN112422646B
CN112422646B CN202011221446.9A CN202011221446A CN112422646B CN 112422646 B CN112422646 B CN 112422646B CN 202011221446 A CN202011221446 A CN 202011221446A CN 112422646 B CN112422646 B CN 112422646B
Authority
CN
China
Prior art keywords
heartbeat
client
server
udp
detection
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.)
Active
Application number
CN202011221446.9A
Other languages
Chinese (zh)
Other versions
CN112422646A (en
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.)
Hangzhou Ezviz Software Co Ltd
Original Assignee
Hangzhou Ezviz Software Co 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 Hangzhou Ezviz Software Co Ltd filed Critical Hangzhou Ezviz Software Co Ltd
Priority to CN202011221446.9A priority Critical patent/CN112422646B/en
Publication of CN112422646A publication Critical patent/CN112422646A/en
Application granted granted Critical
Publication of CN112422646B publication Critical patent/CN112422646B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/14Session management
    • H04L67/143Termination or inactivation of sessions, e.g. event-controlled end of session
    • H04L67/145Termination or inactivation of sessions, e.g. event-controlled end of session avoiding end of session, e.g. keep-alive, heartbeats, resumption message or wake-up for inactive or interrupted session
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L69/00Network arrangements, protocols or services independent of the application payload and not provided for in the other groups of this subclass
    • H04L69/16Implementation or adaptation of Internet protocol [IP], of transmission control protocol [TCP] or of user datagram protocol [UDP]
    • H04L69/164Adaptation or special uses of UDP protocol

Abstract

The invention provides a method, a device and a storage medium for realizing UDP dynamic heartbeat, wherein the method comprises the following steps: when the client side is determined to meet the heartbeat detection initiating condition, initializing a maximum heartbeat interval corresponding to the UDP link, setting the heartbeat interval for keeping the UDP link alive as a preset heartbeat interval, and executing the following operations: performing registration message interaction with the server to register an external network address for keeping alive of a UDP link between the client and the server to the server; when the maximum heartbeat interval corresponding to the UDP link is not determined, carrying out heartbeat message interaction with the server at the beginning of each heartbeat period, carrying out detection message interaction with the server based on the external network address at a preset moment before the end of the heartbeat period so as to determine whether the UDP link is in a keep-alive state, and updating the heartbeat interval or determining the maximum heartbeat interval corresponding to the UDP link according to the keep-alive state of the UDP link; and when determining the maximum heartbeat interval corresponding to the UDP link, carrying out heartbeat message interaction with the server according to the maximum heartbeat interval.

Description

Method, device and storage medium for realizing UDP dynamic heartbeat
Technical Field
The present invention relates to the field of communications technologies, and in particular, to a method, an apparatus, and a storage medium for implementing UDP dynamic heartbeat.
Background
In a conventional client/server architecture system, if a long UDP connection needs to be maintained between a client and a server, the client generally sends a heartbeat message to the server at a fixed time interval (i.e., heartbeat interval) to maintain the keep-alive state of the link.
The heartbeat message sent by the client is finally forwarded to the router of the server through a plurality of routers, and all the routers passing through the link store the quintuple of the source and destination address information of the whole link from the client to the server on the current router: UDP protocol, source address, source port, destination address, and destination port. Because the time for each router to store the quintuple information is not fixed, the keep-alive duration of the whole link is determined by the router which has the shortest time for storing the quintuple information on the link.
If the shortest time for storing the quintuple information by a router on a connection link from a client to a server is N and the heartbeat interval between the client and the server is M, if N is less than M, a heartbeat response message replied by the server cannot reach the client in a time period from M-N to M after the client sends out the heartbeat every time, so that a UDP link cannot be in a keep-alive state and service is interrupted; if N > M, the client may cause additional processing stress on the server because the frequency of sending heartbeat messages is too high.
Disclosure of Invention
In view of the above, an object of the present invention is to provide a method, an apparatus, and a storage medium for implementing UDP dynamic heartbeat, which can reduce processing pressure on a server while maintaining a keep-alive state of a UDP link between a client and the server.
In order to achieve the purpose, the invention provides the following technical scheme:
a first method for implementing UDP dynamic heartbeat is applied to a client, and the method comprises the following steps:
when the client side is determined to meet the heartbeat detection initiating condition, initializing a maximum heartbeat interval corresponding to the UDP link, setting the heartbeat interval for keeping the UDP link alive as a preset heartbeat interval, and executing the following operations:
performing registration message interaction with the server to register an external network address for keeping alive of a UDP link between the client and the server to the server;
circularly executing the following operations until determining the maximum heartbeat interval corresponding to the UDP link: performing first heartbeat message interaction with a server at the beginning of each heartbeat cycle, and performing detection message interaction with the server at a preset time before the end of the heartbeat cycle based on the external network address to determine whether the UDP link is in a keep-alive state, if so, taking a heartbeat interval after increasing a first preset time length as a heartbeat interval of the next heartbeat cycle, otherwise, determining the heartbeat interval of the previous heartbeat cycle as a maximum heartbeat interval corresponding to the UDP link;
and after determining the maximum heartbeat interval corresponding to the UDP link, performing second heartbeat message interaction with the server according to the maximum heartbeat interval until the client side is determined to meet the heartbeat detection initiating condition again.
A second method for implementing UDP dynamic heartbeat, applied to a server, includes:
performing registration message interaction with the client to enable the client to register an external network address for keeping the UDP link between the client and the server alive into the server; the registration message interaction is carried out after a client side determines that the client side meets a heartbeat detection initiating condition, initializes a maximum heartbeat interval corresponding to the UDP link and sets a heartbeat interval for keeping the UDP link alive as a preset heartbeat interval;
circularly executing the following operations until the maximum heartbeat interval corresponding to the UDP link is determined by the client:
performing first heartbeat message interaction with a client side, wherein the first heartbeat message interaction is performed when each heartbeat cycle of the client side starts;
and performing detection message interaction with the client based on the external network address so as to: the client determines whether the UDP link is in a keep-alive state, when the UDP link is in the keep-alive state, the heartbeat interval is increased by a first preset time length and then is used as the heartbeat interval of the next heartbeat cycle, and when the UDP link is determined not to be in the keep-alive state, the heartbeat interval of the previous heartbeat cycle is determined as the maximum heartbeat interval corresponding to the UDP link; the detection message interaction is carried out at a preset moment before the end of the heartbeat cycle at the client side;
and performing second heartbeat message interaction with the client side until the heartbeat detection initiating condition is determined to be met by the client side again, wherein the second heartbeat message interaction is performed according to the maximum heartbeat interval after the maximum heartbeat interval corresponding to the UDP link is determined by the client side.
A first device for implementing UDP dynamic heartbeat is applied to a client, and the device comprises: a processor, and a non-transitory computer readable storage medium connected to the processor by a bus;
the non-transitory computer readable storage medium storing one or more computer programs executable by the processor; the processor, when executing the one or more computer programs, implements the steps of:
when the client side is determined to meet the heartbeat detection initiating condition, initializing a maximum heartbeat interval corresponding to the UDP link, setting the heartbeat interval for keeping the UDP link alive as a preset heartbeat interval, and executing the following operations:
performing registration message interaction with the server to register an external network address for keeping alive of a UDP link between the client and the server to the server;
circularly executing the following operations until determining the maximum heartbeat interval corresponding to the UDP link: performing first heartbeat message interaction with a server at the beginning of each heartbeat cycle, and performing detection message interaction with the server at a preset time before the end of the heartbeat cycle based on the external network address to determine whether the UDP link is in a keep-alive state, if so, taking a heartbeat interval after increasing a first preset time length as a heartbeat interval of the next heartbeat cycle, otherwise, determining the heartbeat interval of the previous heartbeat cycle as a maximum heartbeat interval corresponding to the UDP link;
and after determining the maximum heartbeat interval corresponding to the UDP link, performing second heartbeat message interaction with the server according to the maximum heartbeat interval until the client side is determined to meet the heartbeat detection initiating condition again.
The second kind of device for implementing UDP dynamic heartbeat is applied to a server, and the device includes: a processor, and a non-transitory computer readable storage medium connected with the processor through a bus;
the non-transitory computer readable storage medium storing one or more computer programs executable by the processor; the processor, when executing the one or more computer programs, implements the steps of:
performing registration message interaction with the client to enable the client to register an external network address for keeping the UDP link between the client and the server alive into the server; the registration message interaction is carried out after a client determines that the client meets a heartbeat detection initiating condition, initializes the maximum heartbeat interval corresponding to the UDP link and sets the heartbeat interval for keeping the UDP link alive as a preset heartbeat interval;
circularly executing the following operations until the maximum heartbeat interval corresponding to the UDP link is determined by the client:
performing first heartbeat message interaction with a client side, wherein the first heartbeat message interaction is performed at the beginning of each heartbeat cycle of the client side;
and performing detection message interaction with the client based on the external network address so as to: the client determines whether the UDP link is in a keep-alive state, when the UDP link is in the keep-alive state, the heartbeat interval is increased by a first preset time length and then is used as the heartbeat interval of the next heartbeat cycle, and when the UDP link is determined not to be in the keep-alive state, the heartbeat interval of the previous heartbeat cycle is determined as the maximum heartbeat interval corresponding to the UDP link; the detection message interaction is carried out at a preset moment before the end of the heartbeat cycle at the client side;
and performing second heartbeat message interaction with the client side until the heartbeat detection initiating condition is determined to be met by the client side again, wherein the second heartbeat message interaction is performed according to the maximum heartbeat interval after the maximum heartbeat interval corresponding to the UDP link is determined by the client side.
A non-transitory computer readable storage medium storing instructions that, when executed by a processor, cause the processor to perform the steps in either of the two methods of implementing UDP dynamic heartbeat as described above.
According to the technical scheme, after the client side meets the heartbeat detection initiating condition, detection message interaction is carried out on the client side and the server at the preset time before the end of each heartbeat cycle so as to determine whether the UDP link between the client side and the server is in the keep-alive state or not, the heartbeat interval is increased by the first preset time length in the keep-alive state and then serves as the heartbeat interval of the next heartbeat cycle, and finally the maximum heartbeat interval corresponding to the UDP link is determined, so that the client side can carry out heartbeat message interaction with the server according to the maximum heartbeat interval. By applying the method of the invention, on one hand, the maximum heartbeat interval corresponding to the UDP link between the client and the server is determined through detection, so that the UDP link between the client and the server can be ensured to be in a keep-alive state, and on the other hand, because the client and the server finally carry out heartbeat message interaction according to the maximum heartbeat interval corresponding to the UDP link, the processing pressure of the server can be effectively reduced.
Drawings
In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required to be used in the description of the embodiments are briefly introduced below, and it is obvious that the drawings in the description below are only some embodiments of the present application, and it is obvious for those skilled in the art to obtain other drawings based on these drawings without creative efforts.
Fig. 1 is a flowchart of a method for implementing UDP dynamic heartbeat according to an embodiment of the present invention;
FIG. 2 is a flowchart of a method for implementing UDP dynamic heartbeat according to an embodiment of the present invention;
fig. 3 is a flowchart of a method for implementing UDP dynamic heartbeat according to an embodiment of the present invention;
fig. 4 is a flowchart of a method for implementing four UDP dynamic heartbeats according to an embodiment of the present invention;
fig. 5 is a flowchart of a method for implementing five UDP dynamic heartbeats according to an embodiment of the present invention;
fig. 6 is a flowchart of an implementation method of six UDP dynamic heartbeat according to an embodiment of the present invention;
fig. 7 is a flowchart of an implementation method of a seven UDP dynamic heartbeat according to an embodiment of the present invention;
fig. 8 is a flowchart of an implementation method of eight UDP dynamic heartbeats according to an embodiment of the present invention;
fig. 9 is a flowchart of a method for implementing nine UDP dynamic heartbeats according to an embodiment of the present invention;
fig. 10 is a flowchart of an implementation method of a ten UDP dynamic heartbeat according to an embodiment of the present invention;
fig. 11 is a flowchart of an implementation method of an eleven UDP dynamic heartbeat according to an embodiment of the present invention;
fig. 12 is a flowchart of a method for implementing twelve UDP dynamic heartbeat according to an embodiment of the present invention;
fig. 13 is a schematic structural diagram of an apparatus for implementing UDP dynamic heartbeat according to an embodiment of the present invention;
fig. 14 is a schematic structural diagram of an apparatus for implementing UDP dynamic heartbeat according to an embodiment of the present invention.
Detailed Description
The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are only some embodiments of the present application, and not all embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.
In the embodiment of the invention, in a system with a client/server structure, after the client determines that the client meets a heartbeat detection initiating condition, the client performs detection message interaction with the server at a preset time before the end of each heartbeat cycle to determine whether a UDP link between the client and the server is in a keep-alive state, and when the client is in the keep-alive state, the client increases a heartbeat interval by a first preset time length to be used as a heartbeat interval of the next heartbeat cycle, and finally determines a maximum heartbeat interval corresponding to the UDP link, so that the client can perform heartbeat message interaction with the server according to the maximum heartbeat interval, and the aim of reducing the processing pressure of the server under the condition of maintaining the keep-alive state of the UDP link between the client and the server is fulfilled.
The embodiment of the present invention provides an implementation scheme of UDP dynamic heartbeat applied to a client, which is described in detail below with reference to fig. 1 to 7:
referring to fig. 1, fig. 1 is a flowchart of an implementation method for UDP dynamic heartbeat according to an embodiment of the present invention, where the method is applied to a client, and as shown in fig. 1, the method specifically includes the following steps:
step 101, when it is determined that the client side meets the heartbeat detection initiating condition, initializing a maximum heartbeat interval corresponding to the UDP link, setting a heartbeat interval for keep-alive of the UDP link as a preset heartbeat interval, and executing the following operation steps 102 to 104:
102, interacting registration messages with a server to register an external network address for keeping UDP (user Datagram protocol) link between a client and the server alive into the server;
step 103, circularly executing the following operations until determining the maximum heartbeat interval corresponding to the UDP link: performing first heartbeat message interaction with a server at the beginning of each heartbeat cycle, and performing detection message interaction with the server at a preset time before the end of the heartbeat cycle based on the external network address to determine whether the UDP link is in a keep-alive state, if so, taking a heartbeat interval after increasing a first preset time length as a heartbeat interval of the next heartbeat cycle, otherwise, determining the heartbeat interval of the previous heartbeat cycle as a maximum heartbeat interval corresponding to the UDP link;
in this step 103, if the maximum heartbeat interval corresponding to the UDP link is determined, the loop is ended, and the process goes to step 104 to execute.
And step 104, after determining the maximum heartbeat interval corresponding to the UDP link, performing second heartbeat message interaction with the server according to the maximum heartbeat interval until the client is determined to meet the heartbeat detection initiating condition again.
In this step 104, if it is determined again that the client satisfies the heartbeat detection initiation condition, the present flow may be executed again.
As can be seen from the method shown in fig. 1, in this embodiment, after it is determined that the client satisfies the heartbeat detection initiation condition, it is determined whether the UDP link between the client and the server is in the keep-alive state by performing detection packet interaction with the server at the preset time before the end of each heartbeat cycle, and in the keep-alive state, the heartbeat interval is increased by the first preset time length to be used as the heartbeat interval of the next heartbeat cycle, and finally, the maximum heartbeat interval corresponding to the UDP link is determined, so that the client can perform heartbeat packet interaction with the server according to the maximum heartbeat interval. By applying the method of the invention, on one hand, the maximum heartbeat interval corresponding to the UDP link between the client and the server is determined through detection, so that the UDP link between the client and the server can be ensured to be in a keep-alive state, and on the other hand, because the client and the server finally carry out heartbeat message interaction according to the maximum heartbeat interval corresponding to the UDP link, the processing pressure of the server can be effectively reduced.
Referring to fig. 2, fig. 2 is a flowchart of a method for implementing a UDP dynamic heartbeat according to an embodiment of the present invention, where the method is applied to a client, and as shown in fig. 2, the method specifically includes the following steps:
step 201, when it is determined that the client satisfies the heartbeat detection initiating condition, initializing a maximum heartbeat interval corresponding to the UDP link, setting a heartbeat interval for keep alive of the UDP link as a preset heartbeat interval, and executing the following operation steps 2021 to 204:
step 2021, sending a registration message to a third UDP port configured by the server through the first UDP port configured by the client, so that after the server receives the registration message at the third UDP port, the server stores a source IP address and a source port of the registration message as an external network address for keeping the UDP link alive, and returns the stored external network address carried in a registration response message to the client;
in this embodiment, the first UDP port configured in the client is a client-side port of a UDP link between the client and the server; the third UDP port of the server configuration is a server-side port of a UDP link between the client and the server. The client performs registration message interaction with the server by using ports on both sides of a UDP link between the client and the server (i.e., a client-side port and a server-side port).
In this embodiment, the external network address includes an external network IP address and an external network port. The client sends the registration message to a third UDP port configured by the server through the first UDP port, after receiving the registration message, the server can analyze the registration message to obtain a source IP address and a source port of the registration message, and the source IP address and the source port of the registration message are stored as an external network address for keeping the UDP link alive.
Step 2022, the client receives the registration response message returned by the server, and stores the external network address carried in the registration response message as the external network address for keeping the UDP link alive.
In this embodiment, the client stores the extranet address carried in the registration response message as the extranet address used for keep-alive of the UDP link, and may subsequently perform detection message interaction with the server by using the extranet address.
The above steps 2021 to 2022 are detailed refinements of the step 102 shown in fig. 1.
Step 203, circularly executing the following operations until determining the maximum heartbeat interval corresponding to the UDP link: performing first heartbeat message interaction with a server at the beginning of each heartbeat cycle, and performing detection message interaction with the server at a preset time before the end of the heartbeat cycle based on the external network address to determine whether the UDP link is in a keep-alive state, if so, taking a heartbeat interval after increasing a first preset time length as a heartbeat interval of the next heartbeat cycle, otherwise, determining the heartbeat interval of the previous heartbeat cycle as a maximum heartbeat interval corresponding to the UDP link;
in this step 203, if it is determined that the maximum heartbeat interval corresponds to the UDP link, the loop is ended, and the process goes to step 204 to execute.
And 204, after the maximum heartbeat interval corresponding to the UDP link is determined, performing second heartbeat message interaction with the server according to the maximum heartbeat interval until the client is determined to meet the heartbeat detection initiating condition again.
In this step 204, if it is determined again that the client satisfies the heartbeat detection initiation condition, the process may return to step 201 to execute this flow again.
As can be seen from the method shown in fig. 2, in this embodiment, the client performs registration message interaction with the server by using ports on both sides of the UDP link between the client and the server, so that both the server and the client obtain an external network address for keep-alive of the UDP link, and after it is determined that the client satisfies the heartbeat detection initiation condition, it is determined whether the UDP link between the client and the server is in a keep-alive state by performing detection message interaction with the server based on the external network address at a preset time before the end of each heartbeat cycle, and the heartbeat interval is updated or the maximum heartbeat interval corresponding to the UDP is determined accordingly. With the present embodiment, it is possible to reduce the processing pressure of the server while maintaining the keep-alive state of the UDP link between the client and the server.
Referring to fig. 3, fig. 3 is a flowchart of an implementation method of three UDP dynamic heartbeats in the embodiment of the present invention, where the method is applied to a client, and as shown in fig. 3, the method specifically includes the following steps:
step 301, when it is determined that the client satisfies the heartbeat detection initiating condition, initializing a maximum heartbeat interval corresponding to the UDP link, setting a heartbeat interval for keep alive of the UDP link to a preset heartbeat interval, and executing the following operation steps 3021 to 304:
step 3021, sending a registration message to a third UDP port configured by the server through the first UDP port configured by the client, so that after the server receives the registration message at the third UDP port, the server stores a source IP address and a source port of the registration message as an external network address for keeping the UDP link alive, and returns the stored external network address to the client in a registration response message;
in this embodiment, the first UDP port configured in the client is a client-side port of a UDP link between the client and the server; the third UDP port of the server configuration is a server-side port of a UDP link between the client and the server. The client performs registration message interaction with the server by using the two side ports (namely, the client side port and the server side port) of the UDP link between the client and the server.
In this embodiment, the external network address includes an external network IP address and an external network port. The client sends a registration message to a third UDP port configured by the server through the first UDP port, and after receiving the registration message, the server can analyze the registration message to obtain a source IP address and a source port of the registration message, and store the source IP address and the source port of the registration message as an external network address for keeping the UDP link alive.
Step 3022, the client receives the registration response message returned by the server, and stores the external network address carried in the registration response message as the external network address for keeping the UDP link alive.
In this embodiment, the client stores the extranet address carried in the registration response message as the extranet address used for keep-alive of the UDP link, and may subsequently perform detection message interaction with the server by using the extranet address.
The above steps 3021 to 3022 are the same as the steps 2021 to 2022 shown in fig. 2 in terms of the implementation principle, and are specific refinements of the step 101 shown in fig. 1.
Step 3031, circularly executing the following operation steps 3032 to 3033 until determining the maximum heartbeat interval corresponding to the UDP link:
step 3032, sending a first heartbeat message to a third UDP port configured by the server through a first UDP port configured by the client at the beginning of each heartbeat period, and receiving a first heartbeat response message returned by the server after the third UDP port receives the heartbeat message;
in this embodiment, the client performs first heartbeat packet interaction with the server by using ports on both sides of a UDP link between the client and the server (i.e., a client-side port and a server-side port). The client and the server perform first heartbeat message interaction with the server at the beginning of each heartbeat cycle so as to maintain the keep-alive state of a UDP link between the client and the server (two side ports of the UDP link are a first UDP port of the client and a third UDP port of the server respectively).
The above step 3032 is a detailed refinement of the "first heartbeat packet interaction with the server at the start of each heartbeat cycle" in step 103 shown in fig. 1 and step 203 shown in fig. 2.
Step 3033, performing detection message interaction with a server based on the extranet address at a preset time before the end of the heartbeat cycle to determine whether the UDP link is in a keep-alive state, if so, increasing a first preset time length of a heartbeat interval to be used as a heartbeat interval of a next heartbeat cycle, turning to step 3031 to execute, otherwise, determining the heartbeat interval of the previous heartbeat cycle to be a maximum heartbeat interval corresponding to the UDP link, and executing step 304;
in this embodiment, the preset time before the end of the heartbeat cycle may be preset empirically, for example, 3 seconds before the end of the heartbeat cycle. The first preset time period may also be set empirically, for example, the first preset time period is set to 15 seconds.
In this embodiment, at a preset time before the end of the heartbeat cycle, detection message interaction is performed with a server based on the external network address to determine whether the UDP link is in a keep-alive state, and if the UDP link is in the keep-alive state, it indicates that there is still a lifting space in the current heartbeat interval, so that the heartbeat interval can be tried to be increased by a first preset duration to be used as the heartbeat interval of the next heartbeat cycle; if the current heartbeat interval is not in the keep-alive state, it indicates that the current heartbeat interval cannot maintain the keep-alive state of the UDP link, and in view of that the heartbeat interval of the previous heartbeat cycle of the heartbeat cycle can maintain the keep-alive state of the UDP link, the heartbeat interval of the previous heartbeat cycle of the heartbeat cycle is determined as the maximum heartbeat interval corresponding to the UDP link.
In this step 3033, if the maximum heartbeat interval corresponding to the UDP link is determined, the loop is ended, and the loop is turned to step 304 to be executed, and if the maximum heartbeat interval corresponding to the UDP link is not determined, the loop process from step 3031 to step 3033 is executed again.
The above steps 3031 to 3033 are detailed refinements of the step 103 shown in fig. 1 and the step 203 shown in fig. 2.
And step 304, after determining the maximum heartbeat interval corresponding to the UDP link, performing a second heartbeat packet interaction with the server according to the maximum heartbeat interval until determining that the client meets the heartbeat detection initiating condition again.
In step 304, the second heartbeat packet interaction is performed with the server, and the implementation principle that is the same as the first heartbeat packet interaction performed between the client and the server in step 3032 is adopted, that is, the method specifically includes: and sending a second heartbeat message to a third UDP port configured by the server through a first UDP port configured by the client, and receiving a second heartbeat response message returned by the server after the server receives the heartbeat message at the third UDP port.
In this embodiment, the first heartbeat message and the second heartbeat message are actually the same heartbeat message, and the first heartbeat response message and the second heartbeat response message are also the same heartbeat response message, and the difference is only that the timing of the first heartbeat message interaction and the second heartbeat message interaction between the client and the server is different.
In this step 304, after determining the maximum heartbeat interval corresponding to the UDP, the client performs a second heartbeat packet interaction with the server according to the maximum heartbeat interval until determining that the client satisfies the heartbeat detection initiation condition again. When the client determines that the client satisfies the heartbeat detection initiating condition again, the process may return to step 301 to re-execute the present flow.
As can be seen from the method shown in fig. 3, in the embodiment, during the process of detecting and determining the maximum heartbeat interval corresponding to the UDP link, when each heartbeat cycle is started, the client performs heartbeat packet interaction by using the ports on the two sides of the UDP link to maintain the keep-alive state of the UDP link, and thus the client detects and determines the maximum heartbeat interval corresponding to the UDP link. By applying the embodiment, the processing pressure of the server can be reduced under the condition of maintaining the keep-alive state of the UDP link between the client and the server.
Referring to fig. 4, fig. 4 is a flowchart of an implementation method of four UDP dynamic heartbeats in the embodiment of the present invention, where the method is applied to a client, and as shown in fig. 4, the method specifically includes the following steps:
step 401, when it is determined that the client satisfies the heartbeat detection initiating condition, initializing a maximum heartbeat interval corresponding to the UDP link, setting a heartbeat interval for keep alive of the UDP link as a preset heartbeat interval, and executing the following operation steps 4021 to 404:
step 4021, sending a registration message to a third UDP port configured by the server through a first UDP port configured by the client, so that after the server receives the registration message at the third UDP port, a source IP address and a source port of the registration message are stored as an external network address for keeping the UDP link alive, and the stored external network address is carried in a registration response message and returned to the client;
in this embodiment, the first UDP port configured for the client is a client-side port of a UDP link between the client and the server; the third UDP port of the server configuration is a server-side port of a UDP link between the client and the server. The client performs registration message interaction with the server by using ports on both sides of a UDP link between the client and the server (i.e., a client-side port and a server-side port).
In this embodiment, the external network address includes an external network IP address and an external network port. The client sends the registration message to a third UDP port configured by the server through the first UDP port, after receiving the registration message, the server can analyze the registration message to obtain a source IP address and a source port of the registration message, and the source IP address and the source port of the registration message are stored as an external network address for keeping the UDP link alive.
Step 4022, the client receives the registration response message returned by the server, and stores the external network address carried in the registration response message as the external network address for keeping the UDP link alive.
In this embodiment, the client stores the extranet address carried in the registration response message as the extranet address used for keep-alive of the UDP link, and may subsequently perform detection message interaction with the server by using the extranet address.
The above steps 4021 to 4022 are a detailed refinement of step 102 shown in fig. 1.
Step 4031, circularly executing the following operation steps 4032 to 4036 until the maximum heartbeat interval corresponding to the UDP link is determined:
4032, performing first heartbeat message interaction with the server at the beginning of each heartbeat cycle;
4033, at a preset time before the end of the heartbeat cycle, sending a detection message carrying the external network address to a fourth UDP port configured by the server through a second UDP port configured by the client, so that the server sends a detection response message to the external network address from the third UDP port after receiving the detection message at the fourth UDP port;
in this embodiment, the client configures two UDP ports: a first UDP port and a second UDP port; the server is configured with two UDP ports: a third UDP port and a fourth UDP port. The first UDP port and the third UDP port are two side ports of the UDP link; the second UDP port and the fourth UDP port serve the UDP link, and in particular, the second UDP port and the fourth UDP port are used to detect sending and receiving of a packet, respectively.
In this embodiment, the client sends the detection message to a fourth UDP port of the server through the second UDP port, after receiving the detection message at the fourth UDP port, the server sends the detection response message from the third UDP port to the external network address according to the external network address carried in the detection message instead of returning the detection response message through the fourth UDP port, and the detection response message is transmitted to the first UDP port of the client along the UDP link, so that the client can check whether the UDP link is in the keep-alive state according to whether the detection response message is received at the first UDP port within the second preset duration.
4034, whether the client receives a detection response message from the server at the first UDP port within a second preset time period is determined, if yes, the step 4035 is executed, otherwise, the step 4036 is executed;
in this embodiment, the second preset time period may be set empirically, for example, the second preset time period may be set to 3 seconds.
Step 4035, determining that the UDP link is in a keep-alive state, adding a first preset time length to a heartbeat interval to serve as the heartbeat interval of the next heartbeat cycle, and turning to step 4031 to execute;
step 4036, determining that the UDP link is not in a keep-alive state, determining a heartbeat interval of a previous heartbeat period as a maximum heartbeat interval corresponding to the UDP link, ending the loop, and going to step 404;
steps 4031 to 4036 above are detailed refinements of step 103 shown in fig. 1 and step 203 shown in fig. 2.
And step 404, after determining the maximum heartbeat interval corresponding to the UDP link, performing a second heartbeat packet interaction with the server according to the maximum heartbeat interval until determining that the client meets the heartbeat detection initiating condition again.
In this step 404, if it is determined again that the client satisfies the heartbeat detection initiation condition, the process may return to step 401 to execute this flow again.
As can be seen from the method shown in fig. 4, in this embodiment, the client sends, at a preset time before the end of each heartbeat cycle, a detection packet carrying an external network address for keeping the UDP link alive to a fourth UDP port of the server through the second UDP port, so that the server can send a detection response packet to the external network address through the third UDP port to perform keep-alive detection on the UDP link, and thus the client can check whether the UDP link is in a keep-alive state according to whether the detection response packet is received at the first UDP port within the second preset time period, and in the keep-alive state, the heartbeat interval is increased by the first preset time period to be used as a heartbeat interval of a next heartbeat cycle, and finally determine a maximum heartbeat interval corresponding to the UDP link, so that the client can perform heartbeat packet interaction with the server according to the maximum heartbeat interval. By applying the embodiment, the processing pressure of the server can be reduced under the condition of maintaining the keep-alive state of the UDP link between the client and the server.
Referring to fig. 5, fig. 5 is a flowchart of an implementation method of five UDP dynamic heartbeats in the embodiment of the present invention, where the method is applied to a client, and as shown in fig. 5, the method specifically includes the following steps:
step 500a, sending a detection switch request to a server, and receiving a detection switch response returned by the server;
step 500b, determining whether heartbeat detection is allowed according to a switch mark carried by the detection switch response, if the heartbeat detection is not allowed, executing step 500c, otherwise, executing step 501;
in this embodiment, the switch flag includes a value indicating that heartbeat detection is allowed and a value indicating that heartbeat detection is prohibited. When the switch flag carried by the detection switch response is a value indicating that the heartbeat detection is allowed, the heartbeat detection can be determined to be allowed, and when the switch flag carried by the detection switch response is a value indicating that the heartbeat detection is forbidden, the heartbeat detection can be determined not to be allowed.
And 500c, ending the flow.
In this embodiment, when it is determined that heartbeat detection is not allowed, the process is ended, and the UDP link keep-alive between the client and the server may adopt an existing heartbeat packet interaction process.
Step 501, when determining that the client satisfies the heartbeat detection initiating condition, initializing a maximum heartbeat interval corresponding to the UDP link, setting a heartbeat interval for keep-alive of the UDP link as a preset heartbeat interval, and executing the following operation steps 502 to 504:
step 502, performing registration message interaction with a server to register an external network address for keep-alive of a UDP link between a client and the server to the server;
step 503, circularly executing the following operations until determining the maximum heartbeat interval corresponding to the UDP link: performing first heartbeat message interaction with a server at the beginning of each heartbeat cycle, and performing detection message interaction with the server at a preset time before the end of the heartbeat cycle based on the external network address to determine whether the UDP link is in a keep-alive state, if so, taking a heartbeat interval after increasing a first preset time length as a heartbeat interval of the next heartbeat cycle, otherwise, determining the heartbeat interval of the previous heartbeat cycle as a maximum heartbeat interval corresponding to the UDP link;
in this step 503, if the maximum heartbeat interval corresponding to the UDP link is determined, the loop is ended, and the process goes to step 504 to execute.
And step 504, after the maximum heartbeat interval corresponding to the UDP link is determined, performing a second heartbeat packet interaction with the server according to the maximum heartbeat interval until the client is determined to satisfy the heartbeat detection initiating condition again.
In this step 504, if it is determined again that the client satisfies the heartbeat detection initiation condition, the process may return to step 501 to be executed again.
As can be seen from the method shown in fig. 5, in this embodiment, in addition to the advantages of the embodiment shown in fig. 1, before the client performs registration packet interaction with the server to register the external network address for UDP link keep-alive between the client and the server to the server, it is determined whether heartbeat detection is allowed by sending a detection switch request to the server, and a subsequent flow is continuously executed when the detection is allowed, so that the server can turn off and on heartbeat detection according to needs, for example, the detection function of the client can be turned off in some abnormal scenarios, thereby facilitating flexible control of the server on heartbeat detection.
Referring to fig. 6, fig. 6 is a flowchart of an implementation method for six UDP dynamic heartbeat according to an embodiment of the present invention, where the method is applied to a client, and as shown in fig. 6, the method specifically includes the following steps:
step 600a, sending a detection switch request to a server, and receiving a detection switch response returned by the server;
step 600b, determining whether heartbeat detection is allowed according to a switch mark carried by the response of the detection switch, if the heartbeat detection is not allowed, executing step 600c, otherwise, continuing to execute step 601;
in this embodiment, the switch flag includes a value indicating that heartbeat detection is allowed and a value indicating that heartbeat detection is prohibited. When the switch flag carried by the detection switch response is a value indicating that the heartbeat detection is allowed, the heartbeat detection can be determined to be allowed, and when the switch flag carried by the detection switch response is a value indicating that the heartbeat detection is forbidden, the heartbeat detection can be determined not to be allowed.
And step 600c, ending the flow.
In this embodiment, when it is determined that heartbeat detection is not allowed, the keep-alive of the UDP link between the client and the server may use an existing heartbeat packet interaction procedure.
601, initializing a maximum heartbeat interval corresponding to the UDP link when it is determined that the client satisfies a heartbeat detection initiation condition, setting a heartbeat interval for keep-alive of the UDP link to a preset heartbeat interval, and executing the following operation steps 602 to 604:
step 602, performing registration message interaction with a server to register an external network address for keeping the UDP link between the client and the server alive to the server;
step 6031, circularly executing the following operation steps 6032 to 6036 until determining the maximum heartbeat interval corresponding to the UDP link:
step 6032, performing first heartbeat message interaction with the server at the beginning of each heartbeat cycle, and performing detection message interaction with the server based on the extranet address at a preset moment before the end of the heartbeat cycle to determine whether the UDP link is in a keep-alive state, if the UDP link is in the keep-alive state, executing step 6033, otherwise, executing step 6036;
step 6033, calculating an addition result of the heartbeat interval and a first preset time length, judging whether the addition result is larger than an upper limit of the heartbeat interval, if so, executing step 6034, otherwise, executing step 6035;
in this embodiment, the upper limit of the heartbeat interval may be configured in advance at the client (in this case, the embodiment may not include steps 600a to 600 c); or, a heartbeat interval upper limit is pre-configured in the server and the pre-configured heartbeat interval upper limit is carried in a detection switch response returned to the client, so that the client can obtain the heartbeat interval upper limit configured by the server from the detection switch response;
step 6034, determine the preset upper limit of the heartbeat interval as the maximum heartbeat interval corresponding to the UDP link, end the loop, and go to step 604.
Step 6035, setting the heartbeat interval as the addition result, and going to step 6031 to execute;
step 6036, determining the heartbeat interval of the previous heartbeat cycle as the maximum heartbeat interval corresponding to the UDP link, and go to step 604;
the above steps 6031 to 6036 are detailed refinements of the step 103 shown in fig. 1.
And step 604, after determining the maximum heartbeat interval corresponding to the UDP link, performing a second heartbeat packet interaction with the server according to the maximum heartbeat interval until it is determined again that the client meets the heartbeat detection initiating condition.
In this step 604, if it is determined again that the client satisfies the heartbeat detection initiation condition, the process returns to step 601 to execute.
As can be seen from the method shown in fig. 6, in addition to the advantages of the embodiment shown in fig. 5, in this embodiment, by setting the upper limit of the heartbeat interval, the maximum heartbeat interval corresponding to the UDP link between the client and the server may not be too large, so that negative effects caused by network changes when the client performs heartbeat packet interaction with the server according to the maximum heartbeat interval may be avoided.
Referring to fig. 7, fig. 7 is a flowchart of an implementation method of a seven UDP dynamic heartbeat according to an embodiment of the present invention, where the method is applied to a client, and as shown in fig. 7, the method specifically includes the following steps:
step 7011, when the client is started, the client is disconnected and reconnected, the local IP address of the client is changed, the UPD link is disconnected, or the current heartbeat detection period of the client is finished, it is determined that the client meets the heartbeat detection initiation condition;
in this embodiment, when the client is started, the client is disconnected and reconnected (i.e., reconnected to the network after being disconnected), and the local IP address of the client changes, or when the UDP link between the client and the server is disconnected (for example, the heartbeat message sent by the client for 3 consecutive times does not receive the heartbeat response message returned by the server, and the disconnection of the UDP link can be determined at this time), the service communication of the UDP link between the client and the server is affected, so that it can be determined that the client satisfies the heartbeat detection initiating condition, and thus the heartbeat detection is performed again to re-determine the maximum heartbeat interval corresponding to the UDP link between the client and the server, and thus the heartbeat message interaction is performed with the server according to the maximum heartbeat interval.
In addition, in order to prevent network jitter, a heartbeat detection period may be set, for example, 30 minutes is a heartbeat detection period, and the client performs heartbeat detection every 30 minutes. Therefore, in this embodiment, when the client determines that the current heartbeat detection period is finished (the client may set a timer when determining that the client satisfies the heartbeat detection initiation condition, and when the timer reaches the heartbeat detection period, the client may determine that the current heartbeat detection period is finished), it is determined that the client satisfies the heartbeat detection initiation condition, so that the client performs heartbeat detection again in a new heartbeat detection period to re-determine the maximum heartbeat interval corresponding to the UDP link between the client and the server, and performs heartbeat packet interaction with the server according to the maximum heartbeat interval.
Step 7012, initializing a maximum heartbeat interval corresponding to the UDP link, setting a heartbeat interval for keep alive of the UDP link to a preset heartbeat interval, and performing the following operation steps 702 to 704:
step 702, interacting registration messages with the server to register an external network address for keeping alive of a UDP link between the client and the server to the server;
step 703, circularly executing the following operations until determining the maximum heartbeat interval corresponding to the UDP link: performing first heartbeat message interaction with a server at the beginning of each heartbeat cycle, and performing detection message interaction with the server at a preset time before the end of the heartbeat cycle based on the external network address to determine whether the UDP link is in a keep-alive state, if so, taking a heartbeat interval after increasing a first preset time length as a heartbeat interval of the next heartbeat cycle, otherwise, determining the heartbeat interval of the previous heartbeat cycle as a maximum heartbeat interval corresponding to the UDP link;
in this step 703, if the maximum heartbeat interval corresponding to the UDP link is determined, the loop is ended, and step 704 is performed.
Step 704, after determining the maximum heartbeat interval corresponding to the UDP link, performing a second heartbeat packet interaction with the server according to the maximum heartbeat interval until determining that the client satisfies the heartbeat detection initiating condition again.
In this step 704, if it is determined again that the client satisfies the heartbeat detection initiation condition, the process returns to step 7021 to be executed.
As can be seen from the method shown in fig. 7, in this embodiment, when the client starts, the client disconnects and reconnects the network, the local IP address of the client changes, the UPD link is disconnected, or the current heartbeat detection period of the client ends, it is determined that the client satisfies the heartbeat detection initiating condition, so that the heartbeat detection is performed again to re-determine the maximum heartbeat interval corresponding to the UDP link between the client and the server, and thus the heartbeat packet interaction is performed with the server according to the maximum heartbeat interval. The method has the advantages of the first embodiment, can prevent network jitter, and can solve the problem of UDP link disconnection between the client and the server caused by abnormal equipment and network.
The embodiment of the present invention provides an implementation scheme of UDP dynamic heartbeat applied to a server, which is described in detail below with reference to fig. 8 to 12:
referring to fig. 8, fig. 8 is a flowchart of an implementation method for eight UDP dynamic heartbeat according to an embodiment of the present invention, where the method is applied to a server, and as shown in fig. 8, the method specifically includes the following steps:
801, performing registration message interaction with a client to enable the client to register an external network address for keeping a UDP link between the client and a server alive into the server; the registration message interaction is carried out after a client determines that the client meets a heartbeat detection initiating condition, initializes the maximum heartbeat interval corresponding to the UDP link and sets the heartbeat interval for keeping the UDP link alive as a preset heartbeat interval;
step 802, circularly executing the following operation steps 803 to 804 until the maximum heartbeat interval corresponding to the UDP link is determined by the client:
step 803, performing first heartbeat message interaction with the client, wherein the first heartbeat message interaction is performed at the beginning of each heartbeat cycle of the client side;
step 804, performing detection message interaction with the client based on the external network address, so that: the client determines whether the UDP link is in a keep-alive state, when the UDP link is in the keep-alive state, the heartbeat interval is increased by a first preset time length and then is used as the heartbeat interval of the next heartbeat cycle, and the step 802 is executed; when determining that the UDP link is not in the keep-alive state, determining a heartbeat interval of a previous heartbeat cycle as a maximum heartbeat interval corresponding to the UDP link, and turning to step 805 to execute; the detection message interaction is carried out at a preset moment before the end of the heartbeat cycle at the client side;
and 805, performing second heartbeat message interaction with the client side until the heartbeat detection initiating condition is determined to be met by the client side again, wherein the second heartbeat message interaction is performed according to the maximum heartbeat interval after the maximum heartbeat interval corresponding to the UDP link is determined by the client side.
As can be seen from the method shown in fig. 8, in this embodiment, after it is determined that the client satisfies the heartbeat detection initiation condition, the client performs detection packet interaction with the server at a preset time before the end of each heartbeat cycle to determine whether a UDP link between the client and the server is in a keep-alive state, and when the UDP link is in the keep-alive state, the client increases a first preset time to a heartbeat interval to be used as a heartbeat interval of a next heartbeat cycle, and finally determines a maximum heartbeat interval corresponding to the UDP link, so that the client performs heartbeat packet interaction with the server according to the maximum heartbeat interval. By applying the method of the invention, on one hand, the maximum heartbeat interval corresponding to the UDP link between the client and the server is determined through detection, so that the UDP link between the client and the server can be ensured to be in a keep-alive state, and on the other hand, because the client and the server finally carry out heartbeat message interaction according to the maximum heartbeat interval corresponding to the UDP link, the processing pressure of the server can be effectively reduced.
Referring to fig. 9, fig. 9 is a flowchart of a method for implementing nine UDP dynamic heartbeat according to an embodiment of the present invention, where the method is applied to a server, and as shown in fig. 9, the method specifically includes the following steps:
9011, receiving a registration message sent by the client through a first UDP port configured by the client at a third UDP port configured by the server, and storing a source IP address and a source port of the registration message as an external network address for keeping the UDP link alive;
in this embodiment, after determining that the client satisfies a heartbeat detection initiating condition, initializes a maximum heartbeat interval corresponding to the UDP link, and sets a heartbeat interval for keeping the UDP link alive to a preset heartbeat interval, the client sends a registration packet to the server through the first UDP port, thereby triggering a registration packet interaction process with the server.
In this embodiment, the first UDP port configured for the client is a client-side port of a UDP link between the client and the server; the third UDP port of the server configuration is a server-side port of a UDP link between the client and the server. The client performs registration message interaction with the server by using the two side ports (namely, the client side port and the server side port) of the UDP link between the client and the server.
In this embodiment, the external network address includes an external network IP address and an external network port. The client sends the registration message to a third UDP port configured by the server through the first UDP port, after receiving the registration message, the server can analyze the registration message to obtain a source IP address and a source port of the registration message, and the source IP address and the source port of the registration message are stored as an external network address for keeping the UDP link alive.
And 9012, returning the registration response message carried by the stored external network address to the client, so that the client stores the external network address carried in the registration response message as the external network address for keeping the UDP link alive.
In this embodiment, the client stores the extranet address carried in the registration response message as the extranet address used for keep-alive of the UDP link, and may subsequently perform detection message interaction with the server by using the extranet address.
The above steps 9011 to 9012 are specific refinements of step 801 shown in fig. 8.
Step 902, circularly executing the following operation steps 903 to 904 until the maximum heartbeat interval corresponding to the UDP link is determined by the client:
step 903, performing first heartbeat message interaction with the client, wherein the first heartbeat message interaction is performed at the beginning of each heartbeat cycle of the client side;
step 904, performing detection message interaction with the client based on the external network address, so as to: the client determines whether the UDP link is in a keep-alive state, and when the UDP link is in the keep-alive state, the client increases the heartbeat interval by a first preset time length to be used as the heartbeat interval of the next heartbeat cycle, and then the step 902 is executed; when the UDP link is determined not to be in the keep-alive state, determining the heartbeat interval of the previous heartbeat cycle as the maximum heartbeat interval corresponding to the UDP link, and turning to step 905 for execution; the detection message interaction is carried out at a preset moment before the end of the heartbeat cycle at the client side;
and 905, performing second heartbeat message interaction with the client until the heartbeat detection initiating condition is determined to be met by the client again, wherein the second heartbeat message interaction is performed according to the maximum heartbeat interval after the maximum heartbeat interval corresponding to the UDP link is determined by the client side.
As can be seen from the method shown in fig. 9, in this embodiment, the server performs registration packet interaction with the client by using ports on both sides of a UDP link between the client and the server, so that both the server and the client obtain an external network address for keeping the UDP link alive, and after it is determined that the client satisfies a heartbeat detection initiation condition, the client performs detection packet interaction with the server based on the external network address at a preset time before the end of each heartbeat cycle to determine whether the UDP link between the client and the server is in a keep-alive state, and updates a heartbeat interval or determines a maximum heartbeat interval corresponding to the UDP according to the detection packet interaction. By applying the embodiment, the processing pressure of the server can be reduced under the condition of maintaining the keep-alive state of the UDP link between the client and the server.
Referring to fig. 10, fig. 10 is a flowchart of an implementation method of a ten UDP dynamic heartbeat according to an embodiment of the present invention, where the method is applied to a server, and as shown in fig. 10, the method specifically includes the following steps:
step 10011, receiving, at a third UDP port configured by the server, a registration packet sent by the client through the first UDP port configured by the client, and storing a source IP address and a source port of the registration packet as an external network address for keep-alive of the UDP link;
in this embodiment, after determining that the client meets a heartbeat detection initiation condition, initializes a maximum heartbeat interval corresponding to the UDP link, and sets a heartbeat interval for keep-alive of the UDP link to a preset heartbeat interval, the client sends a registration packet to the server through the first UDP port, thereby triggering a registration packet interaction process with the server.
In this embodiment, the first UDP port configured in the client is a client-side port of a UDP link between the client and the server; the third UDP port of the server configuration is a server-side port of a UDP link between the client and the server. The client performs registration message interaction with the server by using ports on both sides of a UDP link between the client and the server (i.e., a client-side port and a server-side port).
In this embodiment, the external network address includes an external network IP address and an external network port. The client sends a registration message to a third UDP port configured by the server through the first UDP port, and after receiving the registration message, the server can analyze the registration message to obtain a source IP address and a source port of the registration message, and store the source IP address and the source port of the registration message as an external network address for keeping the UDP link alive.
Step 10012, returning the stored external network address carried in the registration response message to the client, so that the client stores the external network address carried in the registration response message as the external network address used for keeping the UDP link alive.
In this embodiment, the stored external network address is carried in the registration response message and returned to the client, that is, the server sends the registration response message carrying the external network address to the first UDP port of the client through the third UDP port.
In this embodiment, the client stores the extranet address carried in the registration response message as the extranet address used for keep-alive of the UDP link, and may subsequently perform detection message interaction with the server by using the extranet address.
The above steps 10011 to 10012 are detailed refinements of the step 801 shown in fig. 8.
Step 1002, circularly executing the following operations 1003 to 1004 until the maximum heartbeat interval corresponding to the UDP link is determined by the client:
step 1003, receiving, at a third UDP port configured by the server, a first heartbeat packet sent by the client through the first UDP port configured by the client at the beginning of each heartbeat cycle, and returning a first heartbeat response packet from the third UDP port configured by the server to the first UDP port configured by the client.
In this embodiment, the server performs heartbeat packet interaction with the client by using the ports on both sides of the UDP link between the client and the server (i.e., the client-side port and the server-side port). The client and the server perform heartbeat message interaction with the server at the beginning of each heartbeat period so as to maintain the keep-alive state of a UDP link (a first UDP port of the client and a third UDP port of the server when two side ports of the UDP link are respectively used) between the client and the server.
The above step 1003 is a detailed refinement of the step 803 shown in fig. 8 and the step 903 shown in fig. 9.
Step 1004, performing detection message interaction with the client based on the external network address, so as to: the client determines whether the UDP link is in a keep-alive state, when the UDP link is in the keep-alive state, the heartbeat interval is increased by a first preset time length and then is used as the heartbeat interval of the next heartbeat cycle, and the step 1002 is executed; when it is determined that the UDP link is not in the keep-alive state, determining a heartbeat interval of a previous heartbeat cycle as a maximum heartbeat interval corresponding to the UDP link, and turning to step 1005 to execute; the detection message interaction is carried out at a preset moment before the end of the heartbeat cycle at the client side;
in this embodiment, the preset time before the end of the heartbeat cycle may be preset empirically, for example, 3 seconds before the end of the heartbeat cycle. The first preset time period may also be set empirically, for example, the first preset time period is set to 15 seconds.
In this embodiment, the server performs detection packet interaction with the client based on the extranet address at a preset time before the end of the heartbeat cycle, so that the client can determine whether the UDP link is in a keep-alive state, and accordingly update a heartbeat interval or determine a maximum heartbeat interval corresponding to the UDP link.
And 1005, performing second heartbeat message interaction with the client side until the heartbeat detection initiating condition is determined to be met by the client side again, wherein the second heartbeat message interaction is performed according to the maximum heartbeat interval after the maximum heartbeat interval corresponding to the UDP link is determined by the client side.
In this embodiment, the second heartbeat packet interaction with the client uses the same implementation principle as the first heartbeat packet interaction with the client, and specifically includes: and receiving a second heartbeat message sent by the client through the first UDP port configured by the client at the beginning of each heartbeat period at a third UDP port configured by the server, and returning a second heartbeat response message from the third UDP port configured by the server to the first UDP port configured by the client.
As can be seen from the method shown in fig. 10, in the embodiment, during the process of detecting and determining the maximum heartbeat interval corresponding to the UDP link, when each heartbeat cycle is started, the client performs heartbeat packet interaction by using the ports on the two sides of the UDP link to maintain the keep-alive state of the UDP link, and thus the client detects and determines the maximum heartbeat interval corresponding to the UDP link. With the present embodiment, it is possible to reduce the processing pressure of the server while maintaining the keep-alive state of the UDP link between the client and the server.
Referring to fig. 11, fig. 11 is a flowchart of an implementation method of an eleven UDP dynamic heartbeat according to an embodiment of the present invention, where the method is applied to a server, and as shown in fig. 11, the method specifically includes the following steps:
step 11011, receiving a registration message sent by the client through a first UDP port configured by the client at a third UDP port configured by the server, and storing a source IP address and a source port of the registration message as an external network address for keeping the UDP link alive;
in this embodiment, after determining that the client satisfies a heartbeat detection initiating condition, initializes a maximum heartbeat interval corresponding to the UDP link, and sets a heartbeat interval for keeping the UDP link alive to a preset heartbeat interval, the client sends a registration packet to the server through the first UDP port, thereby triggering a registration packet interaction process with the server.
In this embodiment, the first UDP port configured in the client is a client-side port of a UDP link between the client and the server; the third UDP port of the server configuration is a server-side port of a UDP link between the client and the server. The client performs registration message interaction with the server by using the two side ports (namely, the client side port and the server side port) of the UDP link between the client and the server.
In this embodiment, the external network address includes an external network IP address and an external network port. The client sends a registration message to a third UDP port configured by the server through the first UDP port, and after receiving the registration message, the server can analyze the registration message to obtain a source IP address and a source port of the registration message, and store the source IP address and the source port of the registration message as an external network address for keeping the UDP link alive.
And 11012, returning the stored external network address carried in the registration response message to the client so that the client stores the external network address carried in the registration response message as the external network address for keeping the UDP link alive.
In this embodiment, the client stores the extranet address carried in the registration response message as the extranet address used for keep-alive of the UDP link, and may subsequently perform detection message interaction with the server by using the extranet address.
The above steps 11011 to 11012 are specific refinements of step 801 shown in fig. 8.
Step 1102, circularly executing the following operation steps 1103 to 11042 until the maximum heartbeat interval corresponding to the UDP link is determined by the client:
1103, performing first heartbeat message interaction with the client, wherein the first heartbeat message interaction is performed at the beginning of each heartbeat cycle of the client side;
step 11041, receiving, at a fourth UDP port configured by the server, a detection packet carrying the external network address, sent by the client through a second UDP port configured by the client at a preset time before the end of the heartbeat cycle;
step 11042, sending a detection response message to the external network address through a third UDP port configured by the server, so that when the client receives the detection response message from the server through the first UDP port within a second preset time length, the client determines that the UDP link is in a keep-alive state, and after adding a first preset time length to a heartbeat interval, the heartbeat interval is used as a heartbeat interval of a next heartbeat cycle, and the step 1102 is executed; and when the detection response message from the server is not received at the first UDP port within the second preset time duration, determining that the UDP link is not in the keep-alive state, determining a heartbeat interval of a previous heartbeat cycle as a maximum heartbeat interval corresponding to the UDP link, and executing step 1105.
Step 1105, performing second heartbeat packet interaction with the client side until the heartbeat detection initiation condition is determined to be satisfied by the client side again, where the second heartbeat packet interaction is performed according to the maximum heartbeat interval after the maximum heartbeat interval corresponding to the UDP link is determined by the client side.
As can be seen from the method shown in fig. 11, in this embodiment, the client sends, by using the second UDP port, the detection packet carrying the outer network address for keeping the UDP link alive to the fourth UDP port of the server at the preset time before the end of each heartbeat cycle, so that the server can send the detection response packet to the outer network address through the third UDP port to perform keep-alive detection on the UDP link, so that the client can check whether the UDP link is in the keep-alive state according to whether the detection response packet is received at the first UDP port within the second preset time duration, and when the UDP link is in the keep-alive state, the heartbeat interval is increased by the first preset time duration and then serves as the heartbeat interval of the next heartbeat cycle, and finally determines the maximum heartbeat interval corresponding to the UDP link, so that the client can perform heartbeat packet interaction with the server according to the maximum heartbeat interval. By applying the embodiment, the processing pressure of the server can be reduced under the condition of maintaining the keep-alive state of the UDP link between the client and the server.
Referring to fig. 12, fig. 12 is a flowchart of a method for implementing a twelve UDP dynamic heartbeat according to an embodiment of the present invention, where the method is applied to a server, and as shown in fig. 12, the method specifically includes the following steps:
step 1200, receiving a detection switch request sent by a client, returning a detection switch response to the client, so that the client determines whether to allow heartbeat detection according to a switch mark carried by the detection switch response, ending an implementation flow of the UDP dynamic heartbeat at the client side when determining that the heartbeat detection is not allowed, and continuing to execute the implementation flow of the UDP dynamic heartbeat at the client side when determining that the heartbeat detection is allowed;
in this embodiment, the server may set a switch flag according to a requirement, where the switch flag includes a value indicating that heartbeat detection is allowed and a value indicating that heartbeat detection is prohibited.
Step 1201, interacting registration messages with the client to enable the client to register an external network address for keeping alive of a UDP link between the client and the server to the server; the registration message interaction is carried out after a client side determines that the client side meets a heartbeat detection initiating condition, initializes a maximum heartbeat interval corresponding to the UDP link and sets a heartbeat interval for keeping the UDP link alive as a preset heartbeat interval;
step 1202, circularly executing the following operation steps 1203 to 1204 until the maximum heartbeat interval corresponding to the UDP link is determined by the client:
step 1203, performing first heartbeat message interaction with the client side, wherein the first heartbeat message interaction is performed when each heartbeat cycle of the client side starts;
step 1204, performing detection message interaction with the client based on the external network address, so as to: the client determines whether the UDP link is in a keep-alive state, and when the UDP link is in the keep-alive state, the client increases a heartbeat interval by a first preset time length to be used as a heartbeat interval of the next heartbeat cycle, and then the step 1202 is executed; when determining that the UDP link is not in the keep-alive state, determining a heartbeat interval of a previous heartbeat cycle as a maximum heartbeat interval corresponding to the UDP link, and going to step 1205 for execution; the detection message interaction is carried out at a preset moment before the end of the heartbeat cycle at the client side;
and 1205, performing second heartbeat message interaction with the client until the heartbeat detection initiating condition is determined to be met by the client again, wherein the second heartbeat message interaction is performed according to the maximum heartbeat interval after the maximum heartbeat interval corresponding to the UDP link is determined by the client side.
The implementation principle of the above steps 1201 to 1205 is the same as that of the steps 801 to 805 shown in fig. 8.
As can be seen from the method shown in fig. 12, in this embodiment, in addition to the advantages of the embodiment shown in fig. 8, before the client performs registration packet interaction with the server to register the external network address for keeping the UDP link between the client and the server alive to the server, the client first sends a detection switch request to the server to determine whether heartbeat detection is allowed, and when the detection is allowed, the subsequent processes are continuously executed, so that the server can turn off and turn on heartbeat detection according to requirements, for example, the detection function of the client can be turned off in some abnormal scenarios, thereby facilitating flexible control of the server on heartbeat detection.
The embodiment of the present invention further provides a device for implementing UDP dynamic heartbeat, which is described in detail below with reference to fig. 13 and 14:
referring to fig. 13, fig. 13 is a schematic structural diagram of an apparatus for implementing UDP dynamic heartbeat according to an embodiment of the present invention, where the apparatus is applied to a client, and as shown in fig. 13, the apparatus includes: a processor 1301, and a non-transitory computer readable storage medium 1302 connected to the processor 1301 through a bus;
the non-transitory computer readable storage medium 1302 storing one or more computer programs executable by the processor 1301; the processor 1301, when executing the one or more computer programs, performs the steps of:
when the client side is determined to meet the heartbeat detection initiating condition, initializing a maximum heartbeat interval corresponding to the UDP link, setting the heartbeat interval used for keeping the UDP link alive as a preset heartbeat interval, and executing the following operations:
performing registration message interaction with the server to register an external network address for keeping alive of a UDP link between the client and the server to the server;
circularly executing the following operations until determining the maximum heartbeat interval corresponding to the UDP link: performing heartbeat message interaction with a server at the beginning of each heartbeat cycle, performing detection message interaction with the server based on the external network address at a preset time before the end of the heartbeat cycle to determine whether the UDP link is in a keep-alive state, if so, increasing a heartbeat interval by a first preset time length to be used as a heartbeat interval of the next heartbeat cycle, otherwise, determining the heartbeat interval of the previous heartbeat cycle as a maximum heartbeat interval corresponding to the UDP link;
and after determining the maximum heartbeat interval corresponding to the UDP link, performing heartbeat message interaction with the server according to the maximum heartbeat interval until determining that the client meets the heartbeat detection initiating condition again.
In the arrangement shown in figure 13 of the drawings,
the external network address comprises an external network IP address and an external network port;
the processor 1301, interacting with a server in a registration message to register an external network address for keep alive of a UDP link between a client and the server to the server, includes:
sending a registration message to a third UDP port configured by the server through a first UDP port configured by the client, so that after the server receives the registration message at the third UDP port, a source IP address and a source port of the registration message are stored as an outer network address for keeping the UDP link alive, and the stored outer network address is carried in a registration response message and returned to the client;
and the client receives a registration response message returned by the server, and stores the external network address carried in the registration response message as the external network address for keeping the UDP link alive.
In the arrangement shown in figure 13 of the drawings,
the processor 1301, performing heartbeat packet interaction with the server, includes:
sending a heartbeat message to a third UDP port configured by the server through a first UDP port configured by the client, and receiving a heartbeat response message returned by the server after the third UDP port receives the heartbeat message.
In the arrangement shown in figure 13 of the drawings,
the processor 1301, performing detection packet interaction with a server based on the extranet address at a preset time before the end of the heartbeat cycle to determine whether the UDP link is in a keep-alive state, includes:
sending a detection message carrying the external network address to a fourth UDP port configured by the server through a second UDP port configured by the client at a preset time before the end of the heartbeat cycle, so that the server sends a detection response message to the external network address from a third UDP port after receiving the detection message at the fourth UDP port;
if the client receives a detection response message from the server at the first UDP port within a second preset time, determining that the UDP link is in a keep-alive state;
and if the client does not receive the detection response message from the server at the first UDP port within the second preset time, determining that the UDP link is not in a keep-alive state.
In the arrangement shown in figure 13 of the drawings,
the processor 1301, before performing registration message interaction with the server to register an external network address for keep alive of a UDP link between the client and the server with the server, further includes:
sending a detection switch request to a server, and receiving a detection switch response returned by the server;
determining whether heartbeat detection is allowed or not according to a switch mark carried by the detection switch response, if the heartbeat detection is not allowed, ending the process, otherwise, continuously executing the operation and the subsequent operation steps of registering the external network address for keeping the UDP link between the client and the server alive into the server;
wherein the switch flag includes a value indicating that heartbeat detection is allowed and a value indicating that heartbeat detection is prohibited.
In the arrangement shown in figure 13 of the drawings,
presetting a heartbeat interval upper limit; or, the server is pre-configured with a heartbeat interval upper limit and carries the pre-configured heartbeat interval upper limit in the detection switch response returned to the client;
the processor 1301, which obtains the upper limit of the heartbeat interval from the response of the detection switch;
the processor 1301, after adding a first preset time length to the heartbeat interval, takes the heartbeat interval as the heartbeat interval of the next heartbeat cycle, and includes:
calculating an addition result of the heartbeat interval and the first preset time length;
and judging whether the addition result is greater than the upper limit of the heartbeat interval, if so, determining the upper limit of the preset heartbeat interval as the maximum heartbeat interval corresponding to the UDP link, and otherwise, setting the heartbeat interval as the addition result.
In the arrangement shown in figure 13 of the drawings,
the processor 1301, determining that the client satisfies the heartbeat detection initiating condition, includes:
and when the client is started, the network of the client is disconnected and reconnected, the local IP address of the client is changed, the UPD link is disconnected, or the current heartbeat detection period of the client is finished, determining that the client meets the heartbeat detection initiating condition.
Referring to fig. 14, fig. 14 is a schematic structural diagram of an implementation apparatus for two UDP dynamic heartbeats according to an embodiment of the present invention, where the apparatus is applied to a server, and as shown in fig. 14, the implementation apparatus specifically includes: a processor 1401, and a non-transitory computer-readable storage medium 1402 connected to the processor 1401 via a bus;
the non-transitory computer readable storage medium 1402 storing one or more computer programs executable by the processor 1401; the processor 1401 when executing the one or more computer programs realizes the following steps:
performing registration message interaction with the client so that the client registers an external network address for keeping the UDP link between the client and the server alive into the server; the registration message interaction is carried out after a client side determines that the client side meets a heartbeat detection initiating condition, initializes a maximum heartbeat interval corresponding to the UDP link and sets a heartbeat interval for keeping the UDP link alive as a preset heartbeat interval;
circularly executing the following operations until the maximum heartbeat interval corresponding to the UDP link is determined by the client:
performing first heartbeat message interaction with a client side, wherein the first heartbeat message interaction is performed at the beginning of each heartbeat cycle of the client side;
and performing detection message interaction with the client based on the external network address so as to enable: the client determines whether the UDP link is in a keep-alive state or not, when the UDP link is in the keep-alive state, the heartbeat interval is increased by a first preset duration to serve as the heartbeat interval of the next heartbeat cycle, and when the UDP link is determined not to be in the keep-alive state, the heartbeat interval of the previous heartbeat cycle is determined to be the maximum heartbeat interval corresponding to the UDP link; the detection message interaction is carried out at a preset moment before the end of the heartbeat cycle at the client side;
and performing second heartbeat message interaction with the client until the heartbeat detection initiating condition is determined to be met by the client again, wherein the second heartbeat message interaction is performed according to the maximum heartbeat interval after the maximum heartbeat interval corresponding to the UDP link is determined by the client side.
In the device shown in figure 14 of the drawings,
the external network address comprises an external network IP address and an external network port;
the processor 1401, interacting with a client in a registration message to enable the client to register an external network address for UDP link keep-alive between the client and a server to the server, includes:
receiving a registration message sent by a client through a first UDP port configured by the client at a third UDP port configured by the server, and storing a source IP address and a source port of the registration message as an external network address for keeping the UDP link alive;
and returning the stored external network address carried in the registration response message to the client so that the client stores the external network address carried in the registration response message as the external network address for keeping the UDP link alive.
In the device shown in figure 14 of the drawings,
the processor 1401, performing heartbeat packet interaction with a client, includes:
receiving a heartbeat message sent by a client through a first UDP port configured by a client at a third UDP port configured by a server;
and returning a heartbeat response message from the third UDP port configured by the server to the first UDP port configured by the client.
In the device shown in figure 14 of the drawings,
the processor 1401, performing detection packet interaction with a client based on the external network address, includes:
receiving a detection message carrying the external network address sent by the client through a second UDP port configured by the client at a preset time before the end of the heartbeat cycle at a fourth UDP port configured by the server;
and sending a detection response message to the external network address through a third UDP port configured by the server, so that the client determines that the UDP link is in a keep-alive state when receiving the detection response message from the server at the first UDP port within a second preset time, and determines that the UDP link is not in the keep-alive state when not receiving the detection response message from the server at the first UDP port within the second preset time.
In the device shown in figure 14 of the drawings,
the processor 1401, interacting with the client through a registration message, so that before the client registers an external network address for UDP link keep-alive between the client and the server to the server, the processor is further configured to:
receiving a detection switch request sent by a client, returning a detection switch response to the client, so that the client determines whether heartbeat detection is allowed according to a switch mark carried by the detection switch response, ending an implementation flow of UDP dynamic heartbeat at one side of the client when determining that the heartbeat detection is not allowed, and continuing to execute the implementation flow of UDP dynamic heartbeat at one side of the client when determining that the heartbeat detection is allowed;
wherein the switch flag includes a value indicating that heartbeat detection is enabled and a value indicating that heartbeat detection is disabled.
Embodiments of the present invention also provide a non-transitory computer readable storage medium storing instructions that, when executed by a processor, cause the processor to perform the steps in the implementation method of UDP dynamic heartbeat as shown in any one of fig. 1-12.
The above description is only for the purpose of illustrating the preferred embodiments of the present invention and is not to be construed as limiting the invention, and any modifications, equivalents, improvements and the like made within the spirit and principle of the present invention should be included in the scope of the present invention.

Claims (15)

1. A realization method of UDP dynamic heartbeat is applied to a client, and is characterized in that the method comprises the following steps:
when the client side is determined to meet the heartbeat detection initiating condition, initializing a maximum heartbeat interval corresponding to the UDP link, setting the heartbeat interval used for keeping the UDP link alive as a preset heartbeat interval, and executing the following operations:
performing registration message interaction with the server to register an external network address for keeping alive of a UDP link between the client and the server to the server;
circularly executing the following operations until determining the maximum heartbeat interval corresponding to the UDP link: performing first heartbeat message interaction with a server by using ports on two sides of the UDP link at the beginning of each heartbeat period, performing detection message interaction with the server based on the ports on two sides of the UDP link and the external network address at a preset time before the end of the heartbeat period to determine whether the UDP link is in a keep-alive state, if so, increasing a first preset time length for a heartbeat interval to serve as the heartbeat interval of the next heartbeat period, otherwise, determining the heartbeat interval of the previous heartbeat period as the maximum heartbeat interval corresponding to the UDP link;
and after determining the maximum heartbeat interval corresponding to the UDP link, performing second heartbeat message interaction with the server according to the maximum heartbeat interval until the client side is determined to meet the heartbeat detection initiating condition again.
2. The method of claim 1,
the external network address comprises an external network IP address and an external network port;
registering a server with a registration message interaction to register an extranet address for UDP link keep-alive between a client and the server, comprising:
sending a registration message to a third UDP port configured by the server through a first UDP port configured by the client, so that after the server receives the registration message at the third UDP port, a source IP address and a source port of the registration message are stored as an external network address used for keeping the UDP link alive, and the stored external network address is carried in a registration response message and returned to the client;
and the client receives a registration response message returned by the server, and stores the external network address carried in the registration response message as the external network address for keeping the UDP link alive.
3. The method of claim 2,
carrying out heartbeat message interaction with a server, comprising:
sending a heartbeat message to a third UDP port configured by the server through a first UDP port configured by the client, and receiving a heartbeat response message returned by the server after the third UDP port receives the heartbeat message.
4. The method of claim 2,
performing detection message interaction with a server based on the external network address at a preset time before the end of the heartbeat cycle to determine whether the UDP link is in a keep-alive state, including:
sending a detection message carrying the external network address to a fourth UDP port configured by the server through a second UDP port configured by the client at a preset time before the end of the heartbeat cycle, so that the server sends a detection response message to the external network address from the third UDP port after receiving the detection message at the fourth UDP port;
if the client receives a detection response message from the server at the first UDP port within a second preset time, determining that the UDP link is in a keep-alive state;
and if the client does not receive the detection response message from the server at the first UDP port within the second preset time, determining that the UDP link is not in a keep-alive state.
5. The method of claim 1,
before registering a foreign network address for UDP link keep-alive between the client and the server with the server in a registration message interaction, further comprising:
sending a detection switch request to a server, and receiving a detection switch response returned by the server;
determining whether heartbeat detection is allowed according to a switch mark carried by the detection switch response, if the heartbeat detection is not allowed, ending the process, otherwise, continuously executing the operation of registering an external network address for keeping the UDP link between the client and the server alive into the server and the subsequent operation steps;
wherein the switch flag includes a value indicating that heartbeat detection is enabled and a value indicating that heartbeat detection is disabled.
6. The method of claim 5,
presetting an upper limit of a heartbeat interval;
or the server is pre-configured with a heartbeat interval upper limit and carries the pre-configured heartbeat interval upper limit in a detection switch response returned to the client, and the client obtains the heartbeat interval upper limit from the detection switch response;
after increasing the heartbeat interval by a first preset time length, the heartbeat interval is taken as the heartbeat interval of the next heartbeat cycle, and the method comprises the following steps:
calculating an addition result of the heartbeat interval and the first preset time length;
and judging whether the addition result is greater than the upper limit of the heartbeat interval, if so, determining the upper limit of the preset heartbeat interval as the maximum heartbeat interval corresponding to the UDP link, and otherwise, setting the heartbeat interval as the addition result.
7. The method of claim 1,
determining that the client meets the heartbeat detection initiating condition, including:
and when the client is started, the network of the client is disconnected and reconnected, the local IP address of the client is changed, the UDP link is disconnected, or the current heartbeat detection period of the client is finished, determining that the client meets the heartbeat detection initiating condition.
8. A realization method of UDP dynamic heartbeat is applied to a server, and is characterized in that the method comprises the following steps:
performing registration message interaction with the client to enable the client to register an external network address for keeping the UDP link between the client and the server alive into the server; the registration message interaction is carried out after a client side determines that the client side meets a heartbeat detection initiating condition, initializes a maximum heartbeat interval corresponding to the UDP link and sets a heartbeat interval for keeping the UDP link alive as a preset heartbeat interval;
circularly executing the following operations until the maximum heartbeat interval corresponding to the UDP link is determined by the client:
performing first heartbeat message interaction with the client by using ports on two sides of the UDP link, wherein the first heartbeat message interaction is performed at the beginning of each heartbeat cycle on the client side;
performing detection message interaction with a client based on the two side ports serving the UDP link and the external network address, so as to: the client determines whether the UDP link is in a keep-alive state or not, when the UDP link is in the keep-alive state, the heartbeat interval is increased by a first preset duration to serve as the heartbeat interval of the next heartbeat cycle, and when the UDP link is determined not to be in the keep-alive state, the heartbeat interval of the previous heartbeat cycle is determined to be the maximum heartbeat interval corresponding to the UDP link; the detection message interaction is carried out at a preset moment before the end of the heartbeat cycle at the client side;
and performing second heartbeat message interaction with the client until the heartbeat detection initiating condition is determined to be met by the client again, wherein the second heartbeat message interaction is performed according to the maximum heartbeat interval after the maximum heartbeat interval corresponding to the UDP link is determined by the client side.
9. The method of claim 8,
the external network address comprises an external network IP address and an external network port;
interacting a registration message with a client to cause the client to register an external network address for UDP link keep-alive between the client and a server with the server, comprising:
receiving a registration message sent by a client through a first UDP port configured by the client at a third UDP port configured by the server, and storing a source IP address and a source port of the registration message as an external network address for keeping the UDP link alive;
and returning the stored external network address carried in the registration response message to the client so that the client stores the external network address carried in the registration response message as the external network address for keeping the UDP link alive.
10. The method of claim 9,
carrying out heartbeat message interaction with a client, comprising:
receiving a heartbeat message sent by a client through a first UDP port configured by a client at a third UDP port configured by a server;
and returning a heartbeat response message from the third UDP port configured by the server to the first UDP port configured by the client.
11. The method of claim 9,
and performing detection message interaction with the client based on the external network address, wherein the detection message interaction comprises the following steps:
receiving a detection message carrying the external network address sent by the client through a second UDP port configured by the client at a preset time before the end of the heartbeat cycle at a fourth UDP port configured by the server;
and sending a detection response message to the external network address through a third UDP port configured by the server, so that the client determines that the UDP link is in a keep-alive state when receiving the detection response message from the server at the first UDP port within a second preset time period, and determines that the UDP link is not in the keep-alive state when not receiving the detection response message from the server at the first UDP port within the second preset time period.
12. The method of claim 8,
before registering the client with the server using the registration message interaction to make the client register the external network address for keeping the UDP link alive between the client and the server, the method further includes:
receiving a detection switch request sent by a client, and returning a detection switch response to the client so as to enable: the client determines whether the heartbeat detection is allowed according to the switch mark carried by the detection switch response, ends the realization flow of the UDP dynamic heartbeat at the client side when the heartbeat detection is determined not to be allowed, and continues to execute the realization flow of the UDP dynamic heartbeat at the client side when the heartbeat detection is determined to be allowed;
wherein the switch flag includes a value indicating that heartbeat detection is enabled and a value indicating that heartbeat detection is disabled.
13. An apparatus for implementing UDP dynamic heartbeat, applied to a client, includes: a processor, and a non-transitory computer readable storage medium connected with the processor through a bus;
the non-transitory computer readable storage medium storing one or more computer programs executable by the processor; the processor, when executing the one or more computer programs, implements the steps of:
when the client side is determined to meet the heartbeat detection initiating condition, initializing a maximum heartbeat interval corresponding to the UDP link, setting the heartbeat interval used for keeping the UDP link alive as a preset heartbeat interval, and executing the following operations:
performing registration message interaction with the server to register an external network address for keeping alive of a UDP link between the client and the server to the server;
circularly executing the following operations until determining the maximum heartbeat interval corresponding to the UDP link: performing first heartbeat message interaction with a server by using ports on two sides of the UDP link at the beginning of each heartbeat period, performing detection message interaction with the server based on the ports on two sides of the UDP link and the external network address at a preset time before the end of the heartbeat period to determine whether the UDP link is in a keep-alive state, if so, increasing a first preset time length for a heartbeat interval to serve as the heartbeat interval of the next heartbeat period, otherwise, determining the heartbeat interval of the previous heartbeat period as the maximum heartbeat interval corresponding to the UDP link;
and after determining the maximum heartbeat interval corresponding to the UDP link, performing second heartbeat message interaction with the server according to the maximum heartbeat interval until the client side is determined to meet the heartbeat detection initiating condition again.
14. An apparatus for implementing UDP dynamic heartbeat, applied to a server, the apparatus comprising: a processor, and a non-transitory computer readable storage medium connected to the processor by a bus;
the non-transitory computer readable storage medium storing one or more computer programs executable by the processor; the processor, when executing the one or more computer programs, implements the steps of:
performing registration message interaction with the client to enable the client to register an external network address for keeping the UDP link between the client and the server alive into the server; the registration message interaction is carried out after a client side determines that the client side meets a heartbeat detection initiating condition, initializes a maximum heartbeat interval corresponding to the UDP link and sets a heartbeat interval for keeping the UDP link alive as a preset heartbeat interval;
circularly executing the following operations until the maximum heartbeat interval corresponding to the UDP link is determined by the client:
performing first heartbeat message interaction with a client by using ports on two sides of the UDP link, wherein the first heartbeat message interaction is performed when each heartbeat cycle on the client side starts;
performing detection message interaction with a client based on the two side ports serving the UDP link and the external network address, so as to: the client determines whether the UDP link is in a keep-alive state or not, when the UDP link is in the keep-alive state, the heartbeat interval is increased by a first preset duration to serve as the heartbeat interval of the next heartbeat cycle, and when the UDP link is determined not to be in the keep-alive state, the heartbeat interval of the previous heartbeat cycle is determined to be the maximum heartbeat interval corresponding to the UDP link; the detection message interaction is carried out at a preset moment before the end of the heartbeat cycle at the client side;
and performing second heartbeat message interaction with the client until the heartbeat detection initiating condition is determined to be met by the client again, wherein the second heartbeat message interaction is performed according to the maximum heartbeat interval after the maximum heartbeat interval corresponding to the UDP link is determined by the client side.
15. A non-transitory computer readable storage medium storing instructions which, when executed by a processor, cause the processor to perform the steps in the method for implementation of a UDP dynamic heartbeat as claimed in any one of claims 1 to 7 or the steps in the method for implementation of a UDP dynamic heartbeat as claimed in any one of claims 8 to 12.
CN202011221446.9A 2020-11-05 2020-11-05 Method, device and storage medium for realizing UDP dynamic heartbeat Active CN112422646B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202011221446.9A CN112422646B (en) 2020-11-05 2020-11-05 Method, device and storage medium for realizing UDP dynamic heartbeat

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202011221446.9A CN112422646B (en) 2020-11-05 2020-11-05 Method, device and storage medium for realizing UDP dynamic heartbeat

Publications (2)

Publication Number Publication Date
CN112422646A CN112422646A (en) 2021-02-26
CN112422646B true CN112422646B (en) 2023-04-18

Family

ID=74828702

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202011221446.9A Active CN112422646B (en) 2020-11-05 2020-11-05 Method, device and storage medium for realizing UDP dynamic heartbeat

Country Status (1)

Country Link
CN (1) CN112422646B (en)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116886755B (en) * 2023-09-08 2023-11-17 安擎计算机信息股份有限公司 Keep-alive method and keep-alive device for tested server

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102223257A (en) * 2011-07-25 2011-10-19 莫雅静 Heartbeat interval adjusting method, server, client terminal and communication system
CN102843250A (en) * 2011-06-21 2012-12-26 中兴通讯股份有限公司 Adaptive method and adaptive device of heartbeat cycle
CN103685241A (en) * 2013-11-26 2014-03-26 中国科学院计算技术研究所 Adaptive heartbeat method and adaptive heartbeat system for maintaining long connection of TCP (transmission control protocol)
CN107241453A (en) * 2016-03-28 2017-10-10 华为技术有限公司 A kind of network address translation mapping keepalive method and device
CN109788038A (en) * 2018-12-25 2019-05-21 上海数果科技有限公司 A kind of intelligent heartbeat method
CN112104527A (en) * 2020-11-19 2020-12-18 启迪国信(北京)信息技术有限公司 Optimal heartbeat interval determining method and device, electronic equipment and readable storage medium

Family Cites Families (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103458436B (en) * 2012-05-31 2016-08-03 中兴通讯股份有限公司 The detection method of link keep-alive and device between AC and AP
CN104144159B (en) * 2014-06-26 2016-04-13 腾讯科技(深圳)有限公司 Intelligent heartbeat keepalive method and intelligent heartbeat keep-alive system
CN106922039B (en) * 2015-12-25 2020-06-05 阿里巴巴集团控股有限公司 Heartbeat message sending method and device
CN109547293A (en) * 2018-12-20 2019-03-29 上海数果科技有限公司 Heartbeat data packet transmission method

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102843250A (en) * 2011-06-21 2012-12-26 中兴通讯股份有限公司 Adaptive method and adaptive device of heartbeat cycle
CN102223257A (en) * 2011-07-25 2011-10-19 莫雅静 Heartbeat interval adjusting method, server, client terminal and communication system
CN103685241A (en) * 2013-11-26 2014-03-26 中国科学院计算技术研究所 Adaptive heartbeat method and adaptive heartbeat system for maintaining long connection of TCP (transmission control protocol)
CN107241453A (en) * 2016-03-28 2017-10-10 华为技术有限公司 A kind of network address translation mapping keepalive method and device
CN109788038A (en) * 2018-12-25 2019-05-21 上海数果科技有限公司 A kind of intelligent heartbeat method
CN112104527A (en) * 2020-11-19 2020-12-18 启迪国信(北京)信息技术有限公司 Optimal heartbeat interval determining method and device, electronic equipment and readable storage medium

Also Published As

Publication number Publication date
CN112422646A (en) 2021-02-26

Similar Documents

Publication Publication Date Title
US8244887B2 (en) HTTP push to simulate server-initiated sessions
EP3694160B1 (en) Date transmission method, apparatus and device
US9112780B2 (en) Techniques for processing incoming failure detection protocol packets
EP3188450B1 (en) Reducing false alarms when using network keep-alive messages
US20170150401A1 (en) Traffic offloading method and apparatus
EP3007494B1 (en) Data processing method and device
EP3226481B1 (en) Method for heartbeat packet processing by using proxy, apparatus, and communications system
WO2012174934A1 (en) Adaptive method and device for heartbeat period
US20230300048A1 (en) Tunnel bfd session establishment method and device
WO2015184921A1 (en) Heartbeat communication implementation method, registration center, server and client
US10594844B2 (en) Method and system for wireless network bilateral accelerated transmission
CN112422646B (en) Method, device and storage medium for realizing UDP dynamic heartbeat
JPWO2020063876A5 (en)
CN107528929B (en) ARP (Address resolution protocol) entry processing method and device
EP3977812B1 (en) Methods, systems, and computer readable media for enhanced signaling gateway (sgw) status detection and selection for emergency calls
JP2024503412A (en) Method, network node, and computer-readable medium for dynamically discovering serving network nodes in a core network
EP2693702A1 (en) Method and label switched router (lsr) for initiating label distribution protocol (ldp) session connection establishment
WO2015158058A1 (en) Method and system for implementing call saving and recovery
WO2016206299A1 (en) Session keep-alive method and device
EP3796715B1 (en) Communication method and system with p-cscf urgency timer/indication for bearer modification
US20240007508A1 (en) Method for establishing communication connection and electronic apparatus capable of establishing communication connection
US20220353782A1 (en) Status registration of packet routing nodes
CN112839392B (en) Method, device and system for reestablishing control and configuration protocol session of wireless access point
US20230403173A1 (en) Methods, Entities, and Computer Readable Media for Error Handling
KR20170002510A (en) Communication device, control device, communication system, method for processing received packet, method for controlling communication device, and program

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
GR01 Patent grant
GR01 Patent grant