CN113890894B - Client communication link keep-alive method and device, electronic equipment and storage medium - Google Patents

Client communication link keep-alive method and device, electronic equipment and storage medium Download PDF

Info

Publication number
CN113890894B
CN113890894B CN202111216665.2A CN202111216665A CN113890894B CN 113890894 B CN113890894 B CN 113890894B CN 202111216665 A CN202111216665 A CN 202111216665A CN 113890894 B CN113890894 B CN 113890894B
Authority
CN
China
Prior art keywords
client
keep
alive
server
current
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202111216665.2A
Other languages
Chinese (zh)
Other versions
CN113890894A (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.)
Guangdong Xunwei Information Industry Co ltd
Shenzhen Lian Intellectual Property Service Center
Original Assignee
Guangdong Xunwei Information Industry 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 Guangdong Xunwei Information Industry Co ltd filed Critical Guangdong Xunwei Information Industry Co ltd
Priority to CN202111216665.2A priority Critical patent/CN113890894B/en
Publication of CN113890894A publication Critical patent/CN113890894A/en
Application granted granted Critical
Publication of CN113890894B publication Critical patent/CN113890894B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

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
    • H04L43/00Arrangements for monitoring or testing data switching networks
    • H04L43/08Monitoring or testing based on specific metrics, e.g. QoS, energy consumption or environmental parameters
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L43/00Arrangements for monitoring or testing data switching networks
    • H04L43/10Active monitoring, e.g. heartbeat, ping or trace-route
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D30/00Reducing energy consumption in communication networks
    • Y02D30/70Reducing energy consumption in communication networks in wireless communication networks

Abstract

The invention discloses a client communication link keep-alive method, a client communication link keep-alive device, electronic equipment and a storage medium, and relates to the field of Internet application. It comprises the following steps: acquiring corresponding preset threshold time according to the current network type, and taking the preset threshold time as a keep-alive time threshold of the client; acquiring corresponding preset interval duration according to the current running state, and taking the preset interval duration as a triggering interval period of the client; generating a keep-alive data packet at intervals of the triggering interval period; judging whether the client performs data interaction with the server in the previous trigger interval period to obtain a first check result; sending the keep-alive data packet to a server and starting timing; judging whether the client receives a response result of the server for the keep-alive data packet or not, and obtaining a second checking result; and determining that the client and the server are in a communication connection state. The utility model can reduce flow waste and electric consumption.

Description

Client communication link keep-alive method and device, electronic equipment and storage medium
Technical Field
The invention relates to the field of Internet application, and also relates to the field of artificial intelligence, in particular to a client communication link keep-alive method, a device, electronic equipment and a storage medium.
Background
When the client and the server perform data communication (communication connection) through a long link, in order to ensure effective utilization of network resources, the server does not perform data exchange with the client after a period of time, and at this time, the client and the server disconnect the communication connection (long link) to recover the resources; in addition, in the case of mobile networks, operators may also reclaim network resources because the link has no data traffic for a period of time. These conditions may result in the established long link being no longer available.
In practical operation, in order to ensure stability of long links, and also in order to avoid that the user experience of the user is reduced due to frequent disconnection and reconnection of the client when the client is in use, the client often sends a small data packet at preset fixed time intervals (i.e. fixed trigger interval periods) to keep the links alive, but the data packet often has the following problems when being sent:
1. when data is transmitted at fixed time intervals, there is often a case that a client and a server may have other data interaction in the time, and in the case that the client and the server are already in a link state, if a data packet is further transmitted to keep the client and the server in the link state, unnecessary traffic waste and power consumption are caused.
2. In actual operation, the recovery time of different operator network resources is different, so that the fixed time interval set by people can only be lower than the minimum value under the condition of all recovery times, in this case, the recovery time of the operator network resources can be far longer than the fixed time interval, and thus, the client side can send a plurality of keep-alive data packets in order to avoid reducing the use experience of users, and unnecessary traffic waste and power consumption are caused.
Disclosure of Invention
The embodiment of the invention provides a client communication link keep-alive method, a device, electronic equipment and a storage medium, which are used for solving the problems of larger flow waste and electric quantity consumption existing in the existing client communication link keep-alive mode.
The technical scheme of the invention is as follows: the method for optimizing the keep-alive of the communication link of the client comprises the following steps:
acquiring a current network type connected with a client, searching a preset threshold time corresponding to the current network type in a preset keep-alive time threshold information table according to the current network type, and taking the searched preset threshold time as a keep-alive time threshold of the client;
acquiring the current running state of the client, searching a preset interval duration corresponding to the current running state in a preset trigger interval period information table according to the current running state, and taking the searched preset interval duration as a trigger interval period of the client;
Generating a keep-alive data packet at intervals of the triggering interval period;
judging whether the client performs data interaction with the server in the previous trigger interval period to obtain a first check result;
if the first check result is negative, sending the keep-alive data packet to the server and starting timing;
after the keep-alive time threshold is reached, judging whether the client receives a response result of the server for the keep-alive data packet or not, and obtaining a second check result;
and if the second checking result is yes, determining that the client and the server are in a communication connection state.
Preferably, the method further comprises: monitoring the network type connected with the client in real time; if the network type connected with the client is monitored to be changed, acquiring a preset threshold time corresponding to the current network type, and updating the keep-alive time threshold of the client according to the preset threshold time.
Preferably, the method further comprises: monitoring the running state of the client in real time; if the running state is monitored to change, acquiring a preset interval duration corresponding to the current running state, and updating the triggering interval period of the client according to the preset interval duration.
Preferably, if the running state is monitored to change, a preset interval duration corresponding to the current running state is obtained, and the trigger interval period of the client is updated according to the preset interval duration, and the method further includes: if the current running state of the client is the background running state, judging the current network type of the client; if the current network type is an operator network, executing self-increasing detection operation according to the keep-alive time threshold; if the number of times in the keep-alive time threshold value is counted up to twice, and the response result of the keep-alive data packet sent by the server is not received, stopping executing the self-increasing detection operation;
wherein the self-augmentation detection operation comprises:
s1, if a response result of a keep-alive data packet sent by a server is successfully received within a keep-alive time threshold, adding one to the response times of a current trigger interval period, wherein the initial value of the response times of the current trigger interval period is zero;
s2, if the response times of the current trigger interval period is not less than a preset time threshold, acquiring a period adjustment value according to the sum of the current trigger interval period and a preset accumulated value;
and S3, updating the triggering interval period of the client according to the period adjustment value, zeroing the response times, increasing the preset accumulated value, and returning to the step S1.
Preferably, the preset accumulation value is not greater than a maximum accumulation threshold value and not less than a minimum accumulation threshold value.
Preferably, the method further comprises: if the second checking result is negative, determining that the client and the server are in a communication disconnection state; and when the communication connection between the client and the server is detected, the current running state and the current network type of the client are acquired again.
Preferably, the method further comprises: and if the first check result is yes, determining that the client and the server are in a communication connection state.
The other technical scheme of the invention is as follows: there is provided a client communication link keep-alive optimization apparatus comprising:
the triggering period acquisition module is used for acquiring the current running state of the client, acquiring corresponding preset interval duration according to the current running state, and taking the preset interval duration as the triggering interval period of the client;
the keep-alive threshold acquisition module is used for acquiring the current network type connected with the client, acquiring corresponding preset threshold time according to the current network type, and taking the preset threshold time as a keep-alive time threshold of the client;
The data packet generation module is used for generating keep-alive data packets at intervals of the triggering interval period;
the data interaction checking module is used for judging whether the client and the server perform data interaction in the last trigger interval period to obtain a first checking result, and if the first checking result is negative, the data interaction checking module is used for sending the keep-alive data packet to the server and starting timing;
and the response result checking module is used for judging whether the client receives the response result of the server for the keep-alive data packet after the keep-alive time threshold is reached, obtaining a second checking result, and if the second checking result is yes, determining that the client and the server are in a communication connection state.
The other technical scheme of the invention is as follows: there is provided an electronic device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, the processor implementing the steps of the client communication link keep-alive optimization method when the computer program is executed.
The other technical scheme of the invention is as follows: there is provided a computer readable storage medium storing a computer program which when executed by a processor implements the steps of the client communication link keep-alive optimization method.
Compared with the prior art, the application has the following beneficial effects:
1. before sending a data packet to keep-alive the link state between the client and the server, a precondition is set for whether to send the keep-alive data packet, namely whether to carry out data interaction (including the newly constructed data packet sent by the application and normal information interaction between the client and the server) in a triggering interval period before sending the keep-alive data packet is checked.
2. Under the condition that the client and the server are in the normal link state, the method and the device further monitor the running state change and the network type change of the client in real time to obtain the current running state and the current network type of the client, so that different working modes are respectively adopted to adjust the trigger interval period, and then the working state of the client is adjusted, so that the link keep-alive mode is more reasonable, and flow waste and electric quantity consumption are reduced.
3. The method and the device further distinguish the foreground and background processing of the client, and the client still adopts a fixed time interval to send the keep-alive data packet when in a foreground running state, so that the user experience is ensured; and in the background running state, the method and the device can detect the longest trigger interval period in the current network environment in different modes according to different network types aiming at the situation that the client does not actively perform data interaction any more, so that not only can the method and the device reduce flow waste and electric quantity consumption, but also the link unavailability caused by the recovery of network resources by operators is avoided.
4. When the client is in an operator network and the client is in a background operation, the process of determining the upper limit boundary of the trigger interval period by the client is accelerated by the detection mode of continuously increasing the period adjustment value (the tolerance is a preset accumulated value which is gradually increased, and the preset accumulated value is provided with a maximum preset accumulated value and a minimum preset accumulated value), and the detection mode of the later steady preset accumulated value (always the minimum preset accumulated value) can be close to the upper limit boundary as much as possible in a cell, so that the detection time and detection times of the client are further reduced compared with the whole-course steady span, and the flow waste and the electric consumption are further reduced.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings that are needed in the description of the embodiments of the present invention will be briefly described below, it being obvious that the drawings in the following description are only some embodiments of the present invention, and that other drawings may be obtained according to these drawings without inventive effort for a person skilled in the art.
FIG. 1 is a schematic diagram of the main flow of a client communication link keep-alive optimization method according to a first embodiment of the invention;
FIG. 2 is a schematic diagram of a second embodiment of a client communication link keep-alive optimization arrangement of the invention;
fig. 3 is a schematic structural view of an electronic device according to a third embodiment of the present invention;
fig. 4 is a schematic structural view of a storage medium according to a fourth embodiment of the present invention.
Detailed Description
The following description of the embodiments of the present invention will be made clearly and fully with reference to the accompanying drawings, in which it is evident that the embodiments described are some, but not all embodiments of the invention. All other embodiments, which can be made by those skilled in the art based on the embodiments of the invention without making any inventive effort, are intended to be within the scope of the invention.
The terms "first," "second," "third," and the like in this disclosure are used for descriptive purposes only and are not to be construed as indicating or implying a relative importance or implicitly indicating the number of technical features indicated. Thus, a feature defining "a first", "a second", and "a third" may explicitly or implicitly include at least one such feature. In the description of the present invention, the meaning of "plurality" means at least two, for example, two, three, etc., unless specifically defined otherwise. All directional indications (such as up, down, left, right, front, back … …) in embodiments of the present invention are merely used to explain the relative positional relationship, movement, etc. between the components in a particular gesture (as shown in the drawings), and if the particular gesture changes, the directional indication changes accordingly. Furthermore, the terms "comprise" and "have," as well as any variations thereof, are intended to cover a non-exclusive inclusion. For example, a process, method, system, article, or apparatus that comprises a list of steps or elements is not limited to only those listed steps or elements but may include other steps or elements not listed or inherent to such process, method, article, or apparatus.
Reference herein to "an embodiment" means that a particular feature, structure, or characteristic described in connection with the embodiment may be included in at least one embodiment of the invention. The appearances of such phrases in various places in the specification are not necessarily all referring to the same embodiment, nor are separate or alternative embodiments mutually exclusive of other embodiments. Those of skill in the art will explicitly and implicitly appreciate that the embodiments described herein may be combined with other embodiments.
The server of the application may be an independent server, or may be a cloud server that provides cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (Content Delivery Network, CDN), and basic cloud computing services such as big data and artificial intelligence platforms.
When the client and the server communicate data through long links, the server always breaks the long links to recycle resources after a period of time without data exchange with the client in order to ensure effective utilization of network resources; in addition, in the case of mobile networks, operators may also reclaim network resources when the link has no data communication for a period of time, which may result in the established long link not being available.
Fig. 1 is a flowchart of a method for optimizing keep-alive of a client communication link according to a first embodiment of the invention. It should be noted that, if there are substantially the same results, the method of the present invention is not limited to the flow sequence shown in fig. 1. As shown in fig. 1, the method for optimizing the keep-alive of the communication link of the client comprises the following steps:
s1, acquiring a current network type connected with a client, searching a preset threshold time corresponding to the current network type in a preset keep-alive time threshold information table according to the current network type, and taking the searched preset threshold time as a keep-alive time threshold of the client.
In actual operation, when the threshold time is set, the threshold time of the WIFI network may be 2 seconds, the threshold time of the operator network may be 5 seconds, and the preset threshold time and/or the keep-alive time threshold may be recorded into the keep-alive time threshold information table, and preferably, the step further includes:
when the communication connection with the server is detected to be established, monitoring the network type of the client connection in real time; if the network type connected with the client is monitored to be changed, acquiring a preset threshold time corresponding to the current network type, and updating the keep-alive time threshold of the client according to the preset threshold time.
In this step, after the client is started or after the client is disconnected from the server, the client establishes a communication connection with the server, such as a Socket communication long link, while the client starts to monitor what type of network connection the client is in, and after the monitoring is started, the stand-up obtains the type of network currently used by the client (for example, mobile app).
The network types of the client include: a wireless network, a WIFI network, and an operator network, wherein the operator network includes a plurality of types, such as a GPRS network, an EDGE network, a WCDMA network, a CDMA network, a LET network, and the like.
In the present application, the change of the client network type refers to that the client is transferred from one network connection state to another network connection state, for example, the client is transferred from a no-network connection to a network connection, or the client is transferred from an operator network to a WIFI network, etc.
S2, acquiring the current running state of the client, searching the preset interval duration corresponding to the current running state in a preset trigger interval period information table according to the current running state, and taking the searched preset interval duration as the trigger interval period of the client.
Preferably, the step further comprises: when the communication connection with the server is detected to be established, monitoring the running state of the client in real time; if the running state is monitored to change, acquiring a preset interval duration corresponding to the current running state, and updating a triggering interval period of the client according to the preset interval duration.
In actual operation, the step S1 of acquiring the current network type and the step S2 of acquiring the current running state may be performed separately or simultaneously, where the step of acquiring the current network type and the step of acquiring the current running state are both performed when the client end will establish communication connection with the server, that is, after the monitoring is started, the application will also immediately acquire the current running state of the client end (for example, mobile phone app).
In actual operation, the running state (or working state) of the client in the present application includes: foreground operating state, background operating state, and other states (e.g., suspended state), etc.
The change of the running state of the client in the application refers to that the client is changed from one running state to another running state, for example, the client is transferred from a foreground running state to a background running state.
When in actual work, the preset interval duration and/or the trigger interval period can be recorded into the trigger interval period information table, various preset interval durations are preset in the client according to the real-time running state of the client, different running states correspond to different preset interval durations, when the client and the server just establish communication connection, or after the trigger interval period is reached, the timer arranged in the client can be triggered according to the interval of the trigger interval period, and a keep-alive data packet is built when the timer is triggered.
When in actual work, the triggering interval period of the application mainly refers to interval time (namely preset interval duration) when the timer is triggered at intervals of two adjacent times, and when the running state is monitored to change, the application also responds to the situation that different triggering interval periods are adopted, namely, the application sets different triggering interval periods according to different running states of the client, and the method is as follows:
when the client is in a foreground running state, the specific network type of the client is not distinguished at this time (i.e. the client is not distinguished between the WIFI network and the operator network at this time), the triggering interval periods (i.e. the triggering time of the timer) all adopt the same preset interval duration (e.g. 60 seconds, and can be specifically set by oneself), and the setting mode is as follows:
firstly judging whether a client and a server are in a communication connection state (mainly used for detecting whether a communication link is still available or not, namely, immediately constructing a data packet and sending the data packet to the server to detect whether a response timeout phenomenon exists or not, specifically referring to steps S3-S5 in the application), and then adopting different setting modes according to the judging result of the communication connection state, specifically:
if the client and the server are in a communication connection state, the link is still available (namely, the communication link is in a keep-alive state), and the preset interval duration is set to a certain first fixed value (for example, 60 seconds) at the moment, wherein the first fixed value is used as the preset interval duration and the trigger interval period when the client is in a foreground running state;
If the client and the server are not in the communication connection state, the link is not available (namely, the communication link is in the non-keep-alive state), at the moment, the client actively disconnects the connection state with the server and ends the timer triggering, and after the client and the server reestablish the new communication connection, the triggering interval period is reacquired again according to the current running state of the client.
When the client is in the background running state, the client needs to judge (distinguish) the current network type of the client (i.e. the client needs to distinguish the WIFI network and the operator network at this time), and adopts different trigger interval periods for different network types, and the setting mode is as follows:
firstly, setting a trigger interval period to a certain second fixed value (for example, 200 seconds, and the second fixed value is 2-5 times of the first fixed value), then determining the current network type connected with the client in actual working, and finally adopting different trigger interval period setting modes according to different current network types, wherein the specific steps are as follows:
if the current network type is the WIFI network, the second fixed value is unchanged, and the second fixed value is the triggering interval period when the client is in the background running state and is the WIFI network;
If the current network type is an operator network, acquiring a keep-alive time threshold of the operator network, executing self-increasing detection operation according to the keep-alive time threshold, and prolonging a trigger interval period by executing the self-increasing detection operation, so that an upper limit boundary of the trigger interval period is determined, the detection time and detection times of a client can be reduced, the construction quantity and the transmission quantity of a keep-alive data packet are reduced, the flow waste and the electric quantity consumption are further reduced, and finally the trigger interval period after adjustment (following) is used as the trigger interval period of the application in the operator network and in background operation.
When the client is in other states (e.g., a suspended state): the specific network type of the client is not distinguished at this time, the client only needs to actively disconnect the connection state with the server and end the timer trigger, and the trigger interval period is acquired again according to different working states of the client after the client and the server reestablish new communication connection.
In actual operation, when the self-increasing detection operation is executed according to the keep-alive time threshold, if the response result of the keep-alive data packet sent by the server is accumulated twice within the keep-alive time threshold, the execution of the self-increasing detection operation is stopped, wherein the self-increasing detection operation comprises:
S21, if the response result of the keep-alive data packet sent by the server is successfully received within the keep-alive time threshold, adding one to the response times of the current trigger interval period, wherein the initial value of the response times of the current trigger interval period is zero;
s22, if the response times of the current trigger interval period are not less than a preset time threshold, acquiring a period adjustment value according to the sum of the current trigger interval period and a preset accumulated value;
s23, updating the triggering interval period of the client according to the period adjustment value, zeroing the response times and increasing the preset accumulated value, and returning to the step S21.
When the method and the device actually work, the period adjustment value is divided into effective interval triggering time and ineffective interval triggering time, and then whether the client triggers the timer according to the effective interval triggering time or triggers the timer according to the ineffective interval triggering time is judged.
The valid interval triggering time refers to that the client receives the response result of the server for the keep-alive data packet continuously for 3-5 times when running according to the period adjustment value, the invalid interval triggering time refers to that the client accumulates 2 times when running according to the period adjustment value and does not receive the response result of the server for the keep-alive data packet, and meanwhile, the priority effectiveness of the invalid interval triggering time is larger than the valid interval triggering time, namely, when the client runs according to a certain period adjustment value, if the client accumulates 2 times when not receiving the response result of the server for the keep-alive data packet, the period adjustment value is the invalid interval triggering time, and whether the client continuously receives the response result of the server for the keep-alive data packet is not needed to be considered.
If the client triggers the timer according to the effective interval triggering time, presetting interval span time with sequentially increased multiple groups of tolerance, acquiring a second check result according to the second triggering interval time and each group of interval span time, obtaining a plurality of effective interval triggering times, and taking the effective interval triggering time with the largest value as a period adjustment value of the client when the effective interval time runs;
if the client triggers the timer according to the invalid interval, the client actively disconnects the connection state with the server and ends the timer triggering, after the client and the server reestablish new communication connection, the invalid interval triggering time is initialized to be the last valid time interval, the maximum valid time interval is redetermined according to the valid time interval and the minimum time span, and the redetermined maximum valid time interval is the corrected interval time of the client when the invalid interval time runs;
in actual operation, the first fixed value, the second fixed value, trigger interval period, the sum of preset accumulated values in this application acquire cycle adjustment value and all can set up by oneself as required, simultaneously, this application is when setting up preset accumulated values, can set up the biggest accumulation threshold (like 100 seconds), and minimum accumulation threshold (like 25 seconds), has let this application use more conveniently, simultaneously, in order to explain the technical scheme of this application more clearly, combines the example to explain below:
When the response number of the current trigger interval period is not less than the preset number threshold, that is, when the client is running according to the valid interval trigger time, the period adjustment value is sequentially increased from the second fixed value of 200 seconds, for example, may be 225 seconds, 275 seconds, 350 seconds, 450 seconds and 550 seconds in sequence.
If the client runs according to the above-mentioned certain period adjustment value (for example, 450 seconds), the response result of the server for the keep-alive data packet is accumulated for two times, and then the last valid interval triggering time (for example, 350 seconds) is used as the period adjustment value to enable the client to run.
When a certain period adjustment value (for example, 450 seconds) is an invalid interval triggering time, in order to further reduce the construction quantity and the transmission quantity of the keep-alive data packet, the method can further take the last valid interval triggering time (for example, 350 seconds) as a basis, and redetermine the upper limit boundary of the period adjustment value (triggering interval period) according to a minimum accumulation threshold value each time, wherein the period adjustment value is sequentially increased from a second fixed value of 350 seconds, and can be sequentially 375 seconds, 400 seconds and 425 seconds, and if the period adjustment value is redetermined by the client when the client is in a certain period adjustment value (for example, 425 seconds) or is the valid interval triggering time, the period adjustment value (for example, 425 seconds) is taken as the triggering interval period when the client is in a background running state and is in an operator network; if the period adjustment value is determined to be the invalid interval triggering time again when the client terminal is in a certain period adjustment value (such as 425 seconds), the last valid interval triggering time (such as 400 seconds) of the period adjustment value (such as 425 seconds) is taken as the triggering interval period when the client terminal is in a background running state and is in an operator network.
After determining the upper limit boundary (such as 400 seconds) of the trigger interval period, the client saves the value (such as 400 seconds) in the local database, and when the client monitors that the client is switched to the background state from front to back, the value (such as 400 seconds) saved in the database is directly used as a timer trigger time interval without repeatedly detecting from 200 seconds, so that the detection time and detection times of the client can be reduced, the construction quantity and the transmission quantity of the keep-alive data packet are reduced, and the flow waste and the electric quantity consumption are further reduced.
S3: generating keep-alive data packets at intervals of triggering intervals;
in actual operation, the trigger interval period may also be referred to as a timer trigger time. The client is internally provided with a timer, and a keep-alive data packet is produced while the timer is triggered, wherein the format of the keep-alive data packet is agreed by the client and the server, and the specific components of the format of the data packet are a data packet length bit, a CRC check bit, a data packet header length bit and a data packet header bit, and the specific components are as follows: the data packet length bit occupies 4 bytes and is used for representing the current whole data packet length; the CRC check bit occupies 1 byte, and stores a check code obtained by CRC calculation of a specific numerical value of the length bit of the data packet, so as to check the length correctness of the data packet; the packet header bit occupies 1 byte and is used for representing the packet header occupying length; the packet header bit is at least 1 byte for storing an identification indicating the specific type of the packet.
S41: judging whether the client performs data interaction with the server in the previous trigger interval period to obtain a first check result;
s42: if the first check result is no, a keep-alive data packet is sent to the server and timing is started.
Preferably, the step further comprises: if the first check result is yes, the client and the server are determined to be in a communication connection state.
When the method and the device are in actual work, the data in the data interaction between the client and the server not only comprise the data contained in the keep-alive data packet, but also comprise the data generated by the client and the server during normal data interaction, so that the keep-alive data packet is not sent to the server by the client only in the period of the last trigger interval, and the keep-alive data packet is not sent under the condition of normal data interaction with the server, and therefore, the flow waste and the electric quantity consumption can be reduced, the link unavailability caused by recovery of network resources by operators is avoided, and the detection time and the detection times of the data packet sent by the client are also reduced.
In actual operation, the first checking result comprises that data interaction is not performed and data interaction is performed, and if the data interaction is not performed, a keep-alive data packet is sent to the server; if the data interaction is performed, the client and the server are determined to be in a communication connection state, namely the mobile terminal communication link is in a keep-alive state, and at the moment, the data packet is not sent any more.
S51: after the keep-alive time threshold is reached, judging whether the client receives a response result of the server for the keep-alive data packet, and obtaining a second checking result;
s52: if the second checking result is yes, the client and the server are determined to be in a communication connection state.
Preferably, the step further comprises: if the second checking result is negative, determining that the client and the server are in a communication disconnection state; and when the communication connection between the client and the server is detected, the current running state and the current network type of the client are acquired again.
In actual operation, the second checking result comprises that no response result is received, and the response result is received, if the response result is not received, the client actively disconnects the communication connection established with the server, and ends the timer triggering, and after the client reestablishes the communication connection with the server, the S1-S52 is repeatedly executed; if so, the client continues to operate until no response result is received.
In order to make the client more intelligent when the link is kept alive, thereby improving the use experience of the user, the method for optimizing the keep-alive of the communication link of the client further comprises the following steps:
and S6, when the client monitors that the network type is changed and the client and the server are in a communication connection state, the client actively disconnects the link and ends the timer to trigger, and after a new communication connection is reestablished, the process of the steps S1 to S5 is repeatedly executed.
In this step, when the client monitors that the network type changes, that is, when the client monitors that the mobile phone network link state changes, except that the mobile phone network link state is switched from the meshed state to the non-meshed state (only the timer is required to be ended in this case), the client is required to actively disconnect the link and end the timer to trigger no matter what network type the mobile phone is in (including the network change between different operators and WIFI from the non-meshed state to the meshed state, and the like), and the processes of steps S1 to S5 are repeatedly executed after a new communication link is re-established.
In actual operation, in the application, the client does not distinguish which operator the operator link is specific to during actual operation, that is, the client operates in the same manner for different operators (for example, GPRS, EDGE, WCDMA, CDMA, LET), but the setting manners of the different operators are the same when the threshold time and the timer trigger time are set.
Specifically, under different network types, the operation mode of the client is as follows:
the mobile phone is in a state without network link or in a suspended state: at this time, the client is in an abnormal working state, the client does not send a data packet to the server, and the timer does not work.
The mobile phone is in a WIFI network link state: the operation mode of the client is performed according to the procedures of steps S1 to S5, and the threshold time and the timer triggering time of the client can refer to step S2 specifically, which is not described herein.
The mobile phone is in an operator network link state: the specific operation mode of the client is performed according to the mode of step S2, at this time, the threshold time of the client is not reset in the operation process, but the timer trigger time of the client adopts different setting modes according to different operation states of the client, and how to acquire and keep pace with the new interval trigger period can refer to step S2, which is not described herein.
As shown in fig. 2, a second embodiment of the present invention is to provide a client communication link keep-alive optimization apparatus, including:
the trigger period acquisition module 21 is configured to acquire a current running state of the client, acquire a corresponding preset interval duration according to the current running state, and take the preset interval duration as a trigger interval period of the client;
the keep-alive threshold value acquisition module 22 is configured to acquire a current network type connected to the client, acquire a corresponding preset threshold value time according to the current network type, and take the preset threshold value time as a keep-alive time threshold value of the client;
A data packet generating module 23, configured to generate keep-alive data packets at intervals of a triggering interval period;
the data interaction checking module 24 is used for judging whether the client performs data interaction with the server in the previous trigger interval period to obtain a first checking result, and if the first checking result is negative, a keep-alive data packet is sent to the server and timing is started;
and the response result checking module 25 is used for judging whether the client receives the response result of the server for the keep-alive data packet after the keep-alive time threshold is reached, so as to obtain a second checking result, and if the second checking result is yes, determining that the client and the server are in a communication connection state.
Fig. 3 is a schematic structural view of an electronic device according to a third embodiment of the present invention. As shown in fig. 3, the electronic device 30 includes a processor 31 and a memory 32 coupled to the processor 31. The memory 32 stores program instructions for implementing the mobile-side communication link keep-alive optimization method of any of the embodiments described above. The processor 31 is configured to execute program instructions stored in the memory 32 for pollution abatement monitoring data processing.
The processor 31 may also be referred to as a CPU (Central Processing Unit ). The processor 31 may be an integrated circuit chip with signal processing capabilities. The processor 31 may also be a general purpose processor, a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field Programmable Gate Array (FPGA) or other programmable logic device, discrete gate or transistor logic, discrete hardware components. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like.
The subject application is operational with numerous general purpose or special purpose computer system environments or configurations. For example: personal computers, server computers, hand-held or portable devices, tablet devices, multiprocessor systems, microprocessor-based systems, set top boxes, programmable consumer electronics, network PCs, minicomputers, mainframe computers, distributed computing environments that include any of the above systems or devices, and the like. The application may be described in the general context of computer-executable instructions, such as program modules, being executed by a computer. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform particular tasks or implement particular abstract data types. The application may also be practiced in distributed computing environments where tasks are performed by remote processing devices that are linked through a communications network. In a distributed computing environment, program modules may be located in both local and remote computer storage media including memory storage devices.
Referring to fig. 4, fig. 4 is a schematic structural diagram of a storage medium according to a fourth embodiment of the present invention. The storage medium 40 according to the fourth embodiment of the present invention stores the program instructions 41 capable of implementing all the methods described above, wherein the program instructions 41 may be stored in the storage medium in the form of a software product, and include several instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) or a processor (processor) to execute all or part of the steps of the methods described in the embodiments of the present invention. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a random access Memory (RAM, random Access Memory), a magnetic disk, an optical disk, or other various media capable of storing program codes, or a terminal device such as a computer, a server, a mobile phone, a tablet, or the like.
The method and the device can acquire and process the related data based on the artificial intelligence technology. Among these, artificial intelligence (Artificial Intelligence, AI) is the theory, method, technique and application system that uses a digital computer or a digital computer-controlled machine to simulate, extend and extend human intelligence, sense the environment, acquire knowledge and use knowledge to obtain optimal results.
Artificial intelligence infrastructure technologies generally include technologies such as sensors, dedicated artificial intelligence chips, cloud computing, distributed storage, big data processing technologies, operation/interaction systems, mechatronics, and the like. The artificial intelligence software technology mainly comprises a computer vision technology, a robot technology, a biological recognition technology, a voice processing technology, a natural language processing technology, machine learning/deep learning and other directions.
In the several embodiments provided in the present invention, it should be understood that the disclosed systems, devices, and methods may be implemented in other manners. For example, the apparatus embodiments described above are merely illustrative, e.g., the division of elements is merely a logical functional division, and there may be additional divisions of actual implementation, e.g., multiple elements or components may be combined or integrated into another system, or some features may be omitted, or not performed. Alternatively, the coupling or direct coupling or communication connection shown or discussed with each other may be an indirect coupling or communication connection via some interfaces, devices or units, which may be in electrical, mechanical or other form.
In addition, each functional unit in the embodiments of the present invention may be integrated in one processing unit, or each unit may exist alone physically, or two or more units may be integrated in one unit. The integrated units may be implemented in hardware or in software functional units. The foregoing is only the embodiments of the present invention, and the patent scope of the invention is not limited thereto, but is also covered by the patent protection scope of the invention, as long as the equivalent structures or equivalent processes of the present invention and the contents of the accompanying drawings are changed, or the present invention is directly or indirectly applied to other related technical fields.
While the invention has been described with respect to the above embodiments, it should be noted that modifications can be made by those skilled in the art without departing from the inventive concept, and these are all within the scope of the invention.

Claims (9)

1. A method for optimizing keep-alive of a communication link of a client, comprising:
acquiring a current network type connected with a client, searching a preset threshold time corresponding to the current network type in a preset keep-alive time threshold information table according to the current network type, and taking the searched preset threshold time as a keep-alive time threshold of the client, wherein the current network type comprises a non-network, a WIFI network and an operator network;
Acquiring a current running state of the client, searching a preset interval duration corresponding to the current running state in a preset trigger interval period information table according to the current running state, and taking the searched preset interval duration as a trigger interval period of the client, wherein the current running state comprises a foreground running state, a background running state and a suspension state, and if the client is in the foreground running state and is in a communication connection state with a server, a first fixed value is taken as the trigger interval period of the client;
if the client is in the background running state and the current network type is the WIFI network, taking a second fixed value as a triggering interval period of the client;
if the client is in the background running state and the current network type is the operator network, executing self-increasing detection operation according to the keep-alive time threshold, and if the response result of the keep-alive data packet sent by the server is accumulated twice within the keep-alive time threshold, stopping executing the self-increasing detection operation;
generating a keep-alive data packet at intervals of the triggering interval period;
Judging whether the client performs data interaction with the server in the previous trigger interval period to obtain a first check result;
if the first check result is negative, sending the keep-alive data packet to the server and starting timing;
after the keep-alive time threshold is reached, judging whether the client receives a response result of the server for the keep-alive data packet or not, and obtaining a second check result;
if the second checking result is yes, determining that the client and the server are in a communication connection state;
the self-augmentation detection operation comprises:
s1, if a response result of a keep-alive data packet sent by a server is successfully received within a keep-alive time threshold, adding one to the response times of a current trigger interval period, wherein the initial value of the response times of the current trigger interval period is zero;
s2, if the response times of the current trigger interval period is not less than a preset time threshold, acquiring a period adjustment value according to the sum of the current trigger interval period and a preset accumulated value;
and S3, updating the triggering interval period of the client according to the period adjustment value, zeroing the response times, increasing the preset accumulated value, and returning to the step S1.
2. The client communication link keep-alive optimization method of claim 1, further comprising:
monitoring the network type connected with the client in real time;
if the network type connected with the client is monitored to be changed, acquiring a preset threshold time corresponding to the current network type, and updating the keep-alive time threshold of the client according to the preset threshold time.
3. The client communication link keep-alive optimization method according to claim 1 or 2, further comprising:
monitoring the running state of the client in real time;
if the running state is monitored to change, acquiring a preset interval duration corresponding to the current running state, and updating the triggering interval period of the client according to the preset interval duration.
4. The method of claim 1, wherein the predetermined accumulation value is not greater than a maximum accumulation threshold and not less than a minimum accumulation threshold.
5. The client communication link keep-alive optimization method of claim 1, further comprising:
if the second checking result is negative, determining that the client and the server are in a communication disconnection state;
And when the communication connection between the client and the server is detected, the current running state and the current network type of the client are acquired again.
6. The client communication link keep-alive optimization method of claim 1, further comprising:
and if the first check result is yes, determining that the client and the server are in a communication connection state.
7. A client communication link keep-alive optimization apparatus, comprising:
the keep-alive threshold acquisition module is used for acquiring a current network type connected with a client, acquiring corresponding preset threshold time according to the current network type, and taking the preset threshold time as a keep-alive time threshold of the client, wherein the current network type comprises a non-network, a WIFI network and an operator network;
the system comprises a trigger period acquisition module, a trigger period acquisition module and a control module, wherein the trigger period acquisition module is used for acquiring the current running state of the client, acquiring corresponding preset interval duration according to the current running state, and taking the preset interval duration as the trigger interval period of the client, wherein the current running state comprises a foreground running state, a background running state and a suspension state, and if the client is in the foreground running state and is in a communication connection state with a server, a first fixed value is taken as the trigger interval period of the client;
If the client is in the background running state and the current network type is the WIFI network, taking a second fixed value as a triggering interval period of the client;
if the client is in the background running state and the current network type is the operator network, performing self-increasing detection operation according to the keep-alive time threshold, and if the response result of the keep-alive data packet sent by the server is accumulated twice within the keep-alive time threshold, stopping performing the self-increasing detection operation;
the data packet generation module is used for generating keep-alive data packets at intervals of the triggering interval period;
the data interaction checking module is used for judging whether the client performs data interaction with the server in the last trigger interval period to obtain a first checking result, and if the first checking result is negative, the data interaction checking module is used for sending the keep-alive data packet to the server and starting timing;
the response result checking module is used for judging whether the client receives a response result of the server for the keep-alive data packet after the keep-alive time threshold is reached, so as to obtain a second checking result, and if the second checking result is yes, determining that the client and the server are in a communication connection state;
The self-augmentation detection operation comprises:
s1, if a response result of a keep-alive data packet sent by a server is successfully received within a keep-alive time threshold, adding one to the response times of a current trigger interval period, wherein the initial value of the response times of the current trigger interval period is zero;
s2, if the response times of the current trigger interval period is not less than a preset time threshold, acquiring a period adjustment value according to the sum of the current trigger interval period and a preset accumulated value;
and S3, updating the triggering interval period of the client according to the period adjustment value, zeroing the response times, increasing the preset accumulated value, and returning to the step S1.
8. An electronic device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, characterized in that the processor implements the steps of the client communication link keep-alive optimization method according to any one of claims 1 to 6 when the computer program is executed.
9. A computer readable storage medium storing a computer program, characterized in that the computer program when executed by a processor implements the steps of the client communication link keep-alive optimization method according to any one of claims 1 to 6.
CN202111216665.2A 2021-10-19 2021-10-19 Client communication link keep-alive method and device, electronic equipment and storage medium Active CN113890894B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202111216665.2A CN113890894B (en) 2021-10-19 2021-10-19 Client communication link keep-alive method and device, electronic equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111216665.2A CN113890894B (en) 2021-10-19 2021-10-19 Client communication link keep-alive method and device, electronic equipment and storage medium

Publications (2)

Publication Number Publication Date
CN113890894A CN113890894A (en) 2022-01-04
CN113890894B true CN113890894B (en) 2024-03-01

Family

ID=79003522

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111216665.2A Active CN113890894B (en) 2021-10-19 2021-10-19 Client communication link keep-alive method and device, electronic equipment and storage medium

Country Status (1)

Country Link
CN (1) CN113890894B (en)

Families Citing this family (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114760508A (en) * 2022-04-18 2022-07-15 北京金山云网络技术有限公司 Data source returning processing method, server, electronic equipment and storage medium
CN115086263B (en) * 2022-07-22 2024-04-05 康键信息技术(深圳)有限公司 IM message sending method, system, storage medium and computer equipment of IOS terminal
CN115866019B (en) * 2023-02-23 2023-05-12 北京中电普华信息技术有限公司 Method and device for determining connection keep-alive time
CN116032830B (en) * 2023-03-24 2023-07-21 微网优联科技(成都)有限公司 Network switch interaction method, network switch and network system

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105610913A (en) * 2015-12-22 2016-05-25 用友网络科技股份有限公司 Heartbeat keep-alive method and apparatus for long connection in communication network
CN105978757A (en) * 2016-06-13 2016-09-28 北京容联易通信息技术有限公司 Heartbeat method and system for keeping connection
CN106411627A (en) * 2015-07-31 2017-02-15 博雅网络游戏开发(深圳)有限公司 Network connection detection method and apparatus
CN107249136A (en) * 2017-06-07 2017-10-13 北京潘达互娱科技有限公司 Method for connecting network and device
CN111031598A (en) * 2020-01-08 2020-04-17 Oppo广东移动通信有限公司 Network communication control method, device, communication equipment and storage medium

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106411627A (en) * 2015-07-31 2017-02-15 博雅网络游戏开发(深圳)有限公司 Network connection detection method and apparatus
CN105610913A (en) * 2015-12-22 2016-05-25 用友网络科技股份有限公司 Heartbeat keep-alive method and apparatus for long connection in communication network
CN105978757A (en) * 2016-06-13 2016-09-28 北京容联易通信息技术有限公司 Heartbeat method and system for keeping connection
CN107249136A (en) * 2017-06-07 2017-10-13 北京潘达互娱科技有限公司 Method for connecting network and device
CN111031598A (en) * 2020-01-08 2020-04-17 Oppo广东移动通信有限公司 Network communication control method, device, communication equipment and storage medium

Also Published As

Publication number Publication date
CN113890894A (en) 2022-01-04

Similar Documents

Publication Publication Date Title
CN113890894B (en) Client communication link keep-alive method and device, electronic equipment and storage medium
CN103619056A (en) Method and terminal for reporting sensor data
CN106254179B (en) Heartbeat packet asynchronous control method and device
CN109474494A (en) Equipment detection method, device, server and storage medium
CN104243481B (en) A kind of method and system of power information acquisition advance data processing
CN106557407B (en) Method and device for monitoring equipment load
CN105610913A (en) Heartbeat keep-alive method and apparatus for long connection in communication network
CN102595577B (en) Network connection processing method and AP and BP after a kind of terminal standby wakes up
CN110445683B (en) Server, equipment, method and system for monitoring survival state of server
CN110474975B (en) Heartbeat processing method and device of application program, electronic equipment and storage medium
CN110475223A (en) A kind of method for safety monitoring, device and terminal device
CN104486243B (en) Data transmission method, equipment and system
ATE365433T1 (en) RESTART IN MOBILE COMMUNICATION SYSTEMS
CN104270609A (en) Method, system and device for remote monitoring
CN111328059B (en) Data transmission method, data transmission device and electronic equipment
CN105874773B (en) Task processing device, intelligent equipment, task processing method and baseband processor
CN106803833A (en) Processing method, the apparatus and system of heartbeat in connection long
CN107333287B (en) Network detecting method, network detection device and intelligent terminal
CN108540356B (en) Processing method and processing apparatus
CN114675983A (en) Business data processing method and device, storage medium and electronic equipment
CN106502865A (en) Power consumption dynamic trend analysis method and device based on frequent Sensor monitoring
CN106208385A (en) A kind of power utility check system based on platform of internet of things
CN106375148A (en) Dynamic network heartbeat processing method in instant communication and terminal
CN108566669A (en) A kind of method of terminal intelligent power saving, terminal and the device with store function
CN104104554A (en) Life cycle method and apparatus for detecting data access request

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
TA01 Transfer of patent application right
TA01 Transfer of patent application right

Effective date of registration: 20240131

Address after: 510000 Room 601, No.17 Sicheng Road, Tianhe District, Guangzhou City, Guangdong Province (office use only)

Applicant after: Guangdong XunWei Information Industry Co.,Ltd.

Country or region after: China

Address before: 518000 Room 202, block B, aerospace micromotor building, No.7, Langshan No.2 Road, Xili street, Nanshan District, Shenzhen City, Guangdong Province

Applicant before: Shenzhen LIAN intellectual property service center

Country or region before: China

Effective date of registration: 20240131

Address after: 518000 Room 202, block B, aerospace micromotor building, No.7, Langshan No.2 Road, Xili street, Nanshan District, Shenzhen City, Guangdong Province

Applicant after: Shenzhen LIAN intellectual property service center

Country or region after: China

Address before: 518000 Room 201, building A, No. 1, Qian Wan Road, Qianhai Shenzhen Hong Kong cooperation zone, Shenzhen, Guangdong (Shenzhen Qianhai business secretary Co., Ltd.)

Applicant before: PING AN PUHUI ENTERPRISE MANAGEMENT Co.,Ltd.

Country or region before: China

GR01 Patent grant
GR01 Patent grant