CN110381130B - Keep-alive long connection method, device, communication terminal and storage medium - Google Patents

Keep-alive long connection method, device, communication terminal and storage medium Download PDF

Info

Publication number
CN110381130B
CN110381130B CN201910630172.XA CN201910630172A CN110381130B CN 110381130 B CN110381130 B CN 110381130B CN 201910630172 A CN201910630172 A CN 201910630172A CN 110381130 B CN110381130 B CN 110381130B
Authority
CN
China
Prior art keywords
communication terminal
server
state
heartbeat packet
bright screen
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
CN201910630172.XA
Other languages
Chinese (zh)
Other versions
CN110381130A (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.)
Hunan New Cloudnet Technology Co ltd
Original Assignee
Hunan New Cloudnet Technology 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 Hunan New Cloudnet Technology Co ltd filed Critical Hunan New Cloudnet Technology Co ltd
Priority to CN201910630172.XA priority Critical patent/CN110381130B/en
Publication of CN110381130A publication Critical patent/CN110381130A/en
Application granted granted Critical
Publication of CN110381130B publication Critical patent/CN110381130B/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
    • H04L43/00Arrangements for monitoring or testing packet switching networks
    • H04L43/10Arrangements for monitoring or testing packet switching networks using active monitoring, e.g. heartbeat protocols, polling, ping, trace-route
    • H04L43/103Arrangements for monitoring or testing packet switching networks using active monitoring, e.g. heartbeat protocols, polling, ping, trace-route with adaptive polling, i.e. dynamically adapting the polling rate
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network-specific arrangements or communication protocols supporting networked applications
    • H04L67/14Network-specific arrangements or communication protocols supporting networked applications for session management
    • H04L67/143Network-specific arrangements or communication protocols supporting networked applications for session management provided for session termination, e.g., event controlled end of session
    • H04L67/145Network-specific arrangements or communication protocols supporting networked applications for session management provided for session termination, e.g., event controlled end of session provided for avoiding end of session, e.g. keep-alive, heartbeats, resumption message, wake-up for inactive or interrupted session

Abstract

The invention is suitable for the technical field of network connection, and provides a keep-alive long connection method, a keep-alive long connection device, a communication terminal and a storage medium, wherein the keep-alive long connection method comprises the following steps: acquiring the running state of the communication terminal every first preset time; matching corresponding heartbeat packet sending frequency according to the running state; and sending the heartbeat packet to a server according to the heartbeat packet sending frequency. By acquiring the running state of the mobile terminal and matching different heartbeat packet sending frequencies, the heartbeat packet sending frequency is reasonably controlled, and the service time of the mobile terminal is prolonged.

Description

Keep-alive long connection method, device, communication terminal and storage medium
Technical Field
The present invention belongs to the field of communication technologies, and in particular, to a keep-alive long connection method, an apparatus, a communication terminal, and a storage medium.
Background
With the continuous development of communication technology, various communication terminals are in endless, which bring great convenience to daily production and life of people, for example, mobile terminals such as mobile phones, tablet computers, personal digital assistants, and the like. In order to ensure that the communication function of the communication terminal is not interrupted, a keep-alive long connection mode is usually adopted to implement the communication connection between the communication terminal and the server. The common keep-alive long connection mode is to send heartbeat data packets once every fixed time period, and the keep-alive long connection mode cannot reasonably control the sending frequency of the heartbeat packets, so that the power consumption is high and the memory occupancy rate is high.
Disclosure of Invention
In view of this, embodiments of the present invention provide a keep-alive long connection method, an apparatus, a communication terminal, and a storage medium, so as to solve the problems that the existing keep-alive long connection method cannot reasonably control the heartbeat packet transmission frequency, and is large in power consumption and high in memory occupancy rate.
A first aspect of an embodiment of the present invention provides a keep-alive long connection method, including:
acquiring the running state of the communication terminal every first preset time;
matching corresponding heartbeat packet sending frequency according to the running state;
and sending the heartbeat packet to a server according to the heartbeat packet sending frequency.
In one embodiment, matching the corresponding heartbeat packet transmission frequency according to the operating state includes:
judging whether the running state is a bright screen state or not;
if the running state is a bright screen state, judging whether the communication terminal and the server have data interaction or not in the bright screen state;
if the communication terminal and the server do not generate data interaction in the bright screen state, determining that the communication terminal is in a first running state;
and matching the corresponding heartbeat packet sending frequency according to the first running state.
In one embodiment, after determining whether the operating state is the bright screen state, the method further includes:
if the running state is a non-bright screen state, acquiring the starting time for switching the running state into the non-bright screen state;
judging whether the running state is switched to a bright screen state within second preset time from the starting time;
if the running state is switched to a bright screen state, adjusting the sending frequency of the heartbeat packet;
and sending the heartbeat packet to a server according to the adjusted heartbeat packet sending frequency.
In one embodiment, if the operating state is a bright screen state, determining whether the communication terminal and the server have data interaction in the bright screen state includes:
if the communication terminal is in the bright screen state, the data interaction between the communication terminal and the server occurs, and the communication terminal is determined to be in a second running state;
and according to the second running state, not sending a heartbeat packet to the server.
In one embodiment, sending the heartbeat packet to the server according to the heartbeat packet sending frequency comprises
Detecting whether feedback information sent by a server is received or not within a third preset time period;
if the feedback information sent by the server is not received, judging that the long connection is disconnected;
displaying a first operation instruction option list for a user to select, wherein the first operation instruction option list comprises at least one of continuously sending heartbeat packets to a server and interrupting long connection;
receiving a first operation instruction selected by a user, and executing corresponding operation according to the first operation instruction.
A second aspect of the embodiments of the present invention provides a keep-alive long connection device, including:
the acquisition module is used for acquiring the running state of the communication terminal at intervals of first preset time;
the matching module is used for matching the corresponding heartbeat packet sending frequency according to the running state;
and the sending module is used for sending the heartbeat packet to the server according to the heartbeat packet sending frequency.
In one embodiment, the matching module is further configured to:
judging whether the running state is a bright screen state or not;
if the running state is a bright screen state, judging whether the communication terminal and the server have data interaction or not in the bright screen state;
if the communication terminal and the server do not perform data interaction in the bright screen state, determining that the communication terminal is in a first running state;
and matching the corresponding heartbeat packet sending frequency according to the first running state.
In one embodiment, the matching module is further configured to:
if the communication terminal is in the bright screen state, the data interaction between the communication terminal and the server occurs, and the communication terminal is determined to be in a second running state;
and according to the second running state, not sending a heartbeat packet to the server.
A third aspect of an embodiment of the present invention provides a keep-alive long connection communication terminal, including: a memory, a processor and a computer program stored in the memory and executable on the processor, the processor implementing the steps of the method as described above when executing the computer program.
A fourth aspect of an embodiment of the present invention provides a computer-readable storage medium, including: the computer-readable storage medium stores a computer program which, when executed by a processor, implements the steps of the above-described method.
The embodiment of the invention can match different heartbeat packet sending frequencies according to different running states by acquiring the running state of the communication terminal, and the heartbeat packet sending frequency in the non-bright-screen state is lower than the heartbeat packet sending frequency in the bright-screen state, so that the heartbeat packet sending frequency is reasonably controlled, and the power consumption and the memory occupancy rate of the communication terminal can be effectively reduced.
Drawings
In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings needed for the embodiments or the prior art descriptions will be briefly described below, and it is obvious that the drawings in the following description are only some embodiments of the present invention, and it is obvious for those skilled in the art to obtain other drawings without creative efforts.
Fig. 1 is a schematic flow chart of an implementation of a keep-alive long connection method provided in an embodiment of the present invention;
fig. 2 is a schematic structural diagram of a keep-alive long connecting device provided by an embodiment of the invention;
fig. 3 is a schematic diagram of a keep-alive long connection communication terminal provided by an embodiment of the invention.
Detailed Description
In order to make the technical solutions of the present invention better understood by those skilled in the art, the technical solutions in the embodiments of the present invention will be clearly described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are some embodiments of the present invention, but 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 invention.
The terms "comprises" and "comprising," and any variations thereof, in the description and claims of this invention and the above-described drawings are intended to cover non-exclusive inclusions. For example, a process, method, or system, article, or apparatus that comprises a list of steps or elements is not limited to only those steps or elements listed, but may alternatively include other steps or elements not listed, or inherent to such process, method, article, or apparatus. Furthermore, the terms "first," "second," and "third," etc. are used to distinguish between different objects and are not used to describe a particular order.
Example one
The embodiment provides a keep-alive long connection method, which is applied to a communication terminal, wherein the communication terminal can be a mobile terminal such as a mobile phone, a tablet computer, an electronic school sign, a personal digital assistant and a notebook computer, and can also be a non-mobile terminal such as a personal computer, a desktop computer and a self-service terminal.
As shown in fig. 1, the keep-alive long connection method provided in this embodiment includes:
s10, acquiring the running state of the communication terminal at intervals of first preset time;
in application, the first predetermined time may be set to any time according to actual needs, for example, any time from 1S to 60S. The first preset time may be a time preset by the system or a time defined by a user, and the running state includes a bright screen state and a non-bright screen state, where the bright screen state includes a call state, an information transmission state, and an information search state, and the non-bright screen state includes a sleep state, a power-off state, and the like, which is not particularly limited.
S20, matching the corresponding heartbeat packet sending frequency according to the running state;
in application, different running states correspond to different heartbeat packet sending frequencies, the different heartbeat packet sending frequencies are preset, the different heartbeat packet sending frequencies are respectively associated with the different running states, and the associated information is stored. The heartbeat packet sending frequency in the sleep state can be set to be far lower than that in other running states, and can also be set to be any frequency according to actual needs, for example, in the screen-on state, one heartbeat packet is automatically sent to the server every 1S, and in the screen-off state, one heartbeat packet is sent to the server every 1 min.
In one embodiment, step S20 specifically includes:
judging whether the running state is a bright screen state or not;
if the running state is a bright screen state, judging whether the communication terminal and the server have data interaction or not in the bright screen state;
if the communication terminal and the server do not perform data interaction in the bright screen state, determining that the communication terminal is in a first running state;
and matching the corresponding heartbeat packet sending frequency according to the first running state.
In the application, the judgment is to judge whether the communication terminal is in a bright screen state, detect self screen luminescence for the communication terminal, judge that the communication terminal is in the bright screen state, or detect that internal program software receives an operation instruction of a user and judge that the communication terminal is in the bright screen state, if the user carries out information transmission through the communication terminal, the user needs to wake up the communication terminal in advance.
In the application, the above-mentioned determination of whether data interaction occurs between the communication terminal and the server in the bright screen state may be that whether a connection is further established between the communication terminal and the server in the bright screen state, where the server may be a local server (a server set by a developer) corresponding to the communication terminal, or may be a third server corresponding to some other APP software loaded on the communication terminal, and this is not limited. For example, the communication terminal communicates with another terminal through chat software, or runs other instant communication functions such as a network game, and the like, it is considered that data interaction occurs in the communication terminal, and the data interaction is not limited thereto.
In the application, the above-mentioned determination that no data interaction occurs between the communication terminal and the server may be that the communication terminal runs a standalone game to browse downloaded documents or data, and at this time, it may be considered that no data interaction occurs between the communication terminal and the server, and it is determined that the communication terminal is in the first running state, which is not limited herein.
After the first operation state is determined as the bright screen state, the server determines that the communication terminal does not need to be constantly connected with the server at the moment, and then the corresponding heartbeat packet transmission frequency can be matched, for example, the heartbeat packet is transmitted every 30S, and the transmission frequency is higher than that in the off-screen state, which is beneficial to receiving data transmitted by the server.
In an embodiment, if the operating state is a bright screen state, determining whether the communication terminal and the server perform data interaction in the bright screen state includes:
if the communication terminal is in the bright screen state, the data interaction between the communication terminal and the server occurs, and the communication terminal is determined to be in a second running state;
and according to the second running state, not sending a heartbeat packet to the server.
In the application, the second operation state is that the communication terminal and the server perform data interaction, that is, the communication terminal communicates with other terminals through chat software, or runs a network game, or performs document browsing online, and it is considered that the communication terminal and the server perform data interaction, which is not limited.
In the application, the second operation state includes, but is not limited to, a state in which the communication terminal performs data interaction with the server, and the heartbeat packet is not sent to the server. In a state that the communication terminal and the server perform data interaction, even if the heartbeat packet is not sent, the server delays closing the long connection time because the communication terminal is communicating with the communication terminal. Therefore, in a state where the communication terminal and the server perform data interaction, a long connection between the communication terminal and the server is maintained, but during the data interaction state, the heartbeat packet is not transmitted to the server, i.e., in the second operation state, the transmission frequency of the heartbeat packet is zero.
In the application, after the communication terminal and the server perform data interaction, the communication terminal detects whether data interaction with the server is not performed within a fourth preset time, if so, the current running state of the communication terminal can be obtained, and according to the running state of the communication terminal, the corresponding heartbeat packet sending frequency is selected to keep the long connection alive. The fourth preset time may be set to any time according to actual needs, or may be a time preset by the system, which is not limited. The communication terminal detects whether data interaction is not performed with the server within a fourth preset time, which may be that in a state where chat software operates to perform information interaction, if no information is received or sent within the fourth preset time, the communication terminal is considered not to transmit data interaction with the server, or in a state where a web page operates, if the web page is not updated within the fourth preset time, the communication terminal is considered not to transmit data interaction with the server. The starting time of the fourth preset time may be a time when data interaction is not performed between the communication terminal and the server, and the ending time is a set time period, for example, 10min, if data connection has not occurred within 10min, it is considered that data interaction is not transmitted between the communication terminal and the server, and then the current operating state of the communication terminal may be obtained, and according to the operating state of the communication terminal, the corresponding heartbeat packet transmission frequency is selected to keep the long connection alive.
In an embodiment, after determining whether the operating state is the bright screen state, the method further includes:
if the running state is a non-bright screen state, acquiring the starting time for switching the running state of the communication terminal into the non-bright screen state;
judging whether the operation state of the communication terminal is switched to a bright screen state within second preset time from the starting time;
if the running state is switched to a bright screen state, adjusting the sending frequency of the heartbeat packet;
and sending the heartbeat packet to a server according to the adjusted heartbeat packet sending frequency.
In application, the non-bright screen state is a standby state, and no information is displayed on an interface of the communication terminal.
In the application, the initial time for switching the operation state of the communication terminal to the non-bright-screen state is obtained, and may be the initial time for automatically changing to the standby state under the bright-screen state according to a preset rule, the initial time for switching at this time is recorded by the communication terminal as the initial time, and the preset rule may be that the communication terminal does not receive an operation instruction within 1min in advance and changes to an automatic standby state, or that a user clicks a standby key to enter the standby state, which is not limited herein. It should be noted that if it is detected that the user clicks the standby key to enter the standby state, it indicates that the user does not need to use the communication terminal at present, the heartbeat packet transmission frequency in the non-bright screen state at this time may be further reduced, and if the communication terminal changes to the automatic standby state without receiving an operation instruction within 1min, the heartbeat packet transmission frequency in the bright screen state may be continuously used for a period of time after the communication terminal is switched to the non-bright screen state, where the period of time may be set by the system itself or by the user, and this is not particularly limited.
In the application, the second predetermined time may be set to any time according to actual needs, and may be considered as a starting time at the moment when the bright screen state of the communication terminal is switched to the non-bright screen state, and the ending time is a time period set by the user or the communication terminal. If the communication terminal is always in the bright screen state, at 9: when 00, the user locks the screen, then 9: 00 is determined as the starting time of the second predetermined time, and the time period may be set to 5min until a period of time later, that is, 9: 00-9: and 05, second preset time, wherein in the time period, if the communication terminal is not switched to the bright screen state, the sending frequency of the heartbeat packet is adjusted.
And S30, sending the heartbeat packet to the server according to the heartbeat packet sending frequency.
In the application, the sending frequency of the heartbeat packet is preset in the communication terminal, and the sending frequency of the heartbeat packet includes, but is not limited to, automatically sending a heartbeat packet to the server every 1S, and sending a heartbeat packet to the server every 1min, or may be not sending the heartbeat packet to the server in a certain operating state, where the certain operating state includes, but is not limited to, a second operating state in which data interaction is performed with the server, which is not particularly limited.
In one embodiment, after step S30, the method includes:
detecting whether feedback information sent by a server is received or not within a third preset time period;
if the feedback information sent by the server is not received, judging that the long connection is disconnected;
displaying a first operation instruction option list for a user to select, wherein the first operation instruction option list comprises at least one of continuously sending heartbeat packets to a server and interrupting long connection;
receiving a first operation instruction selected by a user, and executing corresponding operation according to the first operation instruction.
In the application, in the third preset time period, an instant when the heartbeat packet is sent to the server may be regarded as a start time, and an end time is a time period which is self-set by the user or the communication terminal, for example, the third preset time period is a time period of 5S, which is not limited in this respect. The feedback information may be an empty data packet sent by the server, and does not contain any data, so as to maintain the connection between the communication terminal and the server.
In the application, the first operation instruction option list is used for judging that the long connection has been disconnected for the communication terminal, and then two option lists of continuously sending the heartbeat packet to the server and interrupting the long connection are displayed on the interface, which are displayed on the interface of the communication terminal in a form of a table or a form of a sliding interface, and the presentation mode of the first operation instruction option list can be the same as or different from that of the first operation instruction option list, which is not limited.
In other applications, in order to avoid the occurrence of repeated reminding for many times, the feedback information of the server cannot be received within 5s of two consecutive occurrences, and the heartbeat packet is continuously sent to the server by default when the operation instruction of the user is that the heartbeat packet is continuously sent to the server. For example, if the user is in an area with a weak signal at this time and selects to continuously transmit the heartbeat packet to the server, the feedback information of the server may not be received again after 5S, and the user may be repeatedly reminded in this way, which may reduce the user experience.
According to the embodiment, the running state of the communication terminal is obtained, different heartbeat packet sending frequencies are matched, the heartbeat packet sending frequency is reasonably controlled, and the power consumption and the memory occupancy rate of the communication terminal can be effectively reduced.
It should be understood that, the sequence numbers of the steps in the foregoing embodiments do not imply an execution sequence, and the execution sequence of each process should be determined by its function and inherent logic, and should not constitute any limitation to the implementation process of the embodiments of the present invention.
Example two
The present embodiment provides a keep-alive long connection device for executing the method steps in the first embodiment.
As shown in fig. 2, the present invention further provides a keep-alive long connection device 100, comprising:
an obtaining module 10, configured to obtain an operating state of the mobile terminal every first predetermined time interval;
the matching module 20 is configured to match the corresponding heartbeat packet sending frequency according to the running state;
and the sending module 30 is configured to send the heartbeat packet to the server according to the heartbeat packet sending frequency.
In an embodiment, the matching module 20 is specifically configured to:
judging whether the running state is a bright screen state or not;
if the running state is a bright screen state, judging whether the communication terminal and the server have data interaction or not in the bright screen state;
if the communication terminal and the server do not perform data interaction in the bright screen state, determining that the communication terminal is in a first running state;
and matching the corresponding heartbeat packet sending frequency according to the first running state.
In an embodiment, the matching module 20 is further configured to:
if the running state is a non-bright screen state, acquiring the starting time for switching the running state into the non-bright screen state;
judging whether the running state is switched to a bright screen state within second preset time from the starting time;
if the running state is switched to a bright screen state, adjusting the sending frequency of the heartbeat packet;
and sending the heartbeat packet to a server according to the adjusted heartbeat packet sending frequency.
In one embodiment, the matching module 20 is further configured to:
if the communication terminal is in the bright screen state, the data interaction between the communication terminal and the server occurs, and the communication terminal is determined to be in a second running state;
and according to the second running state, not sending a heartbeat packet to the server.
In the application, the second operation state includes, but is not limited to, a state in which the communication terminal and the server perform data interaction, the heartbeat packet is not sent to the server, and the long connection between the communication terminal and the server is continuously maintained, but during the data interaction state, the heartbeat packet is not sent to the server, that is, the second operation state, and the sending frequency of the heartbeat packet is zero.
In one embodiment, keep-alive long connection device 100 further comprises, as shown in fig. 2
The detection module 40 is configured to detect whether feedback information sent by the server is received within a third preset time period;
the judging module 50 is used for judging that the long connection is disconnected if the feedback information sent by the server is not received;
a display module 60, configured to display a first operation instruction option list for a user to select, where the first operation instruction option list includes at least one of continuously sending a heartbeat packet to a server and interrupting a long connection;
the receiving module 70 is configured to receive a first operation instruction selected by a user, and execute a corresponding operation according to the first operation instruction.
According to the embodiment, the running state of the communication terminal is obtained, different heartbeat packet sending frequencies are matched, the heartbeat packet sending frequency is reasonably controlled, and the power consumption and the memory occupancy rate of the communication terminal can be effectively reduced.
EXAMPLE III
Fig. 3 is a schematic diagram of a keep-alive long connection communication terminal according to an embodiment of the present invention. As shown in fig. 3, the keep-alive long connection communication terminal 80 of this embodiment includes: a processor 803, a memory 801 and a computer program 802 stored in the memory 801 and executable on the processor 803. The processor 803 executes the computer program 802 to implement the steps in each keep-alive long connection method embodiment described above, such as the steps S10 to S30 shown in fig. 1. Alternatively, the processor 803 realizes the functions of the modules/units in the above-described device embodiments when executing the computer program 802.
Illustratively, the computer program 802 may be partitioned into one or more modules/units that are stored in the memory 801 and executed by the processor 803 to implement the present invention. The one or more modules/units can be a series of computer program instruction segments capable of performing certain functions for describing the execution of the computer program 802 in the keep-alive long connection communication terminal 80. For example, the computer program 802 may be divided into an acquisition module, a matching module, and a sending module, and each module may specifically function as follows:
the acquisition module is used for acquiring the running state of the communication terminal at intervals of first preset time;
the matching module is used for matching the corresponding heartbeat packet sending frequency according to the running state;
and the sending module is used for sending the heartbeat packet to the server according to the heartbeat packet sending frequency. The keep-alive long connection communication terminal 80 may be a computing device such as a desktop computer, a notebook, a palm computer, and a cloud server. The keep-alive long connection communication terminal can include, but is not limited to, a processor 803, a memory 801. Those skilled in the art will appreciate that fig. 3 is merely an example of a keep-alive long connection communication terminal 80 and does not constitute a limitation of a keep-alive long connection communication terminal 80 and may include more or fewer components than shown, or some components in combination, or different components, e.g., the keep-alive long connection communication terminal may also include an input-output device, a network access device, a bus, etc.
The Processor 803 may be a Central Processing Unit (CPU), other 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, etc. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like.
The memory 801 may be an internal storage unit of the keep-alive long connection communication terminal 80, such as a hard disk or a memory of the keep-alive long connection communication terminal 80. The memory 801 may also be an external storage device of the keep-alive long connection communication terminal 80, such as a plug-in hard disk, a Smart Memory Card (SMC), a Secure Digital (SD) Card, a Flash memory Card (Flash Card), and the like, which are equipped on the keep-alive long connection communication terminal 80. In one embodiment, the memory 801 may also include both internal storage elements and external storage devices for the keep-alive long connection communication terminal 80. The memory 801 is used to store the computer programs and other programs and data required by the keep-alive long connection communication terminal. The memory 801 may also be used to temporarily store data that has been output or is to be output.
It will be apparent to those skilled in the art that, for convenience and brevity of description, only the above-mentioned division of the functional units and modules is illustrated, and in practical applications, the above-mentioned function distribution may be performed by different functional units and modules according to needs, that is, the internal structure of the apparatus is divided into different functional units or modules to perform all or part of the above-mentioned functions. Each functional unit and module in the embodiments may be integrated in one processing unit, or each unit may exist alone physically, or two or more units are integrated in one unit, and the integrated unit may be implemented in a form of hardware, or in a form of software functional unit. In addition, specific names of the functional units and modules are only for convenience of distinguishing from each other, and are not used for limiting the protection scope of the present application. The specific working processes of the units and modules in the system may refer to the corresponding processes in the foregoing method embodiments, and are not described herein again.
In the above embodiments, the descriptions of the respective embodiments have respective emphasis, and reference may be made to the related descriptions of other embodiments for parts that are not described or illustrated in a certain embodiment.
Those of ordinary skill in the art will appreciate that the various illustrative elements and algorithm steps described in connection with the embodiments disclosed herein may be implemented as electronic hardware or combinations of computer software and electronic hardware. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the implementation. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present invention.
In the embodiments provided in the present invention, it should be understood that the disclosed apparatus/communication terminal and method may be implemented in other ways. For example, the above-described embodiments of the apparatus/communication terminal are merely illustrative, and for example, the division of the modules or units is only one logical division, and other divisions may be realized in practice, for example, a plurality of units or components may be combined or integrated into another system, or some features may be omitted, or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection through some interfaces, devices or units, and may be in an electrical, mechanical or other form.
The units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of the embodiment.
In addition, functional units in the embodiments of the present invention may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit. The integrated unit can be realized in a form of hardware, and can also be realized in a form of a software functional unit.
The integrated modules/units, if implemented in the form of software functional units and sold or used as separate products, may be stored in a computer readable storage medium. Based on such understanding, all or part of the flow of the method according to the embodiments of the present invention may also be implemented by a computer program, which may be stored in a computer-readable storage medium, and when the computer program is executed by a processor, the steps of the method embodiments may be implemented. Wherein the computer program comprises computer program code, which may be in the form of source code, object code, an executable file or some intermediate form, etc. The computer-readable medium may include: any entity or device capable of carrying the computer program code, recording medium, usb disk, removable hard disk, magnetic disk, optical disk, computer Memory, Read-Only Memory (ROM), Random Access Memory (RAM), electrical carrier wave signals, telecommunications signals, software distribution medium, and the like. It should be noted that the computer readable medium may contain content that is subject to appropriate increase or decrease as required by legislation and patent practice in jurisdictions, for example, in some jurisdictions, computer readable media does not include electrical carrier signals and telecommunications signals as is required by legislation and patent practice.
The above-mentioned embodiments are only used for illustrating the technical solutions of the present invention, and not for limiting the same; although the present invention has been described in detail with reference to the foregoing embodiments, it will be understood by those of ordinary skill in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some technical features may be equivalently replaced; such modifications and substitutions do not substantially depart from the spirit and scope of the embodiments of the present invention, and are intended to be included within the scope of the present invention.

Claims (8)

1. A keep-alive long connection method, comprising:
acquiring the running state of the communication terminal every first preset time;
matching corresponding heartbeat packet sending frequency according to the running state;
sending a heartbeat packet to a server according to the heartbeat packet sending frequency;
the matching of the corresponding heartbeat packet sending frequency according to the running state comprises the following steps:
judging whether the running state is a bright screen state or not;
if the running state is a bright screen state, judging whether the communication terminal and the server have data interaction or not in the bright screen state;
if the running state is a bright screen state, judging whether the communication terminal and the server have data interaction in the bright screen state, and the method comprises the following steps:
if the communication terminal is in the bright screen state, the data interaction between the communication terminal and the server occurs, and the communication terminal is determined to be in a second running state;
according to the second running state, not sending a heartbeat packet to the server;
after not sending the heartbeat packet to the server according to the second operation state, the method further includes:
detecting whether the communication terminal does not perform data interaction with the server within fourth preset time;
and if the communication terminal does not transmit data interaction with the server, acquiring the current running state of the communication terminal, and selecting the corresponding heartbeat packet transmission frequency to keep the long connection alive according to the running state of the communication terminal.
2. A keep-alive long connection method according to claim 1, wherein matching a corresponding heartbeat packet transmission frequency according to the operation state includes:
judging whether the running state is a bright screen state or not;
if the running state is a bright screen state, judging whether the communication terminal and the server have data interaction or not in the bright screen state;
if the communication terminal and the server do not perform data interaction in the bright screen state, determining that the communication terminal is in a first running state;
and matching the corresponding heartbeat packet sending frequency according to the first running state.
3. A keep-alive long connection method according to claim 2, wherein after determining whether the operation state is a bright screen state, the method further comprises:
if the running state is a non-bright screen state, acquiring the starting time for switching the running state of the communication terminal into the non-bright screen state;
continuously using the heartbeat packet sending frequency in the bright screen state within second preset time after the non-bright screen state is converted;
judging whether the operation state of the communication terminal is switched to a bright screen state within second preset time from the starting time;
if the running state is not switched to the bright screen state within second preset time from the starting time, adjusting the sending frequency of the heartbeat packet;
and sending the heartbeat packet to a server according to the adjusted heartbeat packet sending frequency.
4. A keep-alive long connection method according to claim 1, wherein, according to the heartbeat packet transmission frequency, after transmitting a heartbeat packet to a server, the method comprises:
detecting whether feedback information sent by the server is received or not within a third preset time period;
if the feedback information sent by the server is not received, judging that the long connection is disconnected;
displaying a first operation instruction option list for a user to select, wherein the first operation instruction option list comprises at least one of continuously sending heartbeat packets to a server and interrupting long connection;
receiving a first operation instruction selected by a user, and executing corresponding operation according to the first operation instruction.
5. A keep-alive long connection device, comprising:
the acquisition module is used for acquiring the running state of the communication terminal at intervals of first preset time;
the matching module is used for matching the corresponding heartbeat packet sending frequency according to the running state;
the sending module is used for sending the heartbeat packet to a server according to the heartbeat packet sending frequency;
the matching module is further configured to:
judging whether the running state is a bright screen state or not;
if the running state is a bright screen state, judging whether the communication terminal and the server have data interaction or not in the bright screen state;
the matching module is further configured to:
if the communication terminal is in the bright screen state, the data interaction between the communication terminal and the server occurs, and the communication terminal is determined to be in a second running state;
according to the second running state, not sending a heartbeat packet to the server;
the matching module is further configured to:
after data interaction between the communication terminal and the server occurs, detecting whether the communication terminal does not perform data interaction with the server within fourth preset time;
and if the communication terminal does not transmit data interaction with the server, acquiring the current running state of the communication terminal, and selecting the corresponding heartbeat packet transmission frequency to keep the long connection alive according to the running state of the communication terminal.
6. A keep-alive long connection apparatus as claimed in claim 5, wherein the matching module is further configured to:
judging whether the running state is a bright screen state or not;
if the running state is a bright screen state, judging whether the communication terminal and the server have data interaction or not in the bright screen state;
if the communication terminal and the server do not perform data interaction in the bright screen state, determining that the communication terminal is in a first running state;
and matching the corresponding heartbeat packet sending frequency according to the first running state.
7. A communication terminal 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 method according to any of claims 1 to 4 when executing the computer program.
8. A computer-readable storage medium, in which a computer program is stored which, when being executed by a processor, carries out the steps of the method according to any one of claims 1 to 4.
CN201910630172.XA 2019-07-12 2019-07-12 Keep-alive long connection method, device, communication terminal and storage medium Active CN110381130B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910630172.XA CN110381130B (en) 2019-07-12 2019-07-12 Keep-alive long connection method, device, communication terminal and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910630172.XA CN110381130B (en) 2019-07-12 2019-07-12 Keep-alive long connection method, device, communication terminal and storage medium

Publications (2)

Publication Number Publication Date
CN110381130A CN110381130A (en) 2019-10-25
CN110381130B true CN110381130B (en) 2020-05-29

Family

ID=68253044

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910630172.XA Active CN110381130B (en) 2019-07-12 2019-07-12 Keep-alive long connection method, device, communication terminal and storage medium

Country Status (1)

Country Link
CN (1) CN110381130B (en)

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103491512A (en) * 2012-06-12 2014-01-01 腾讯科技(深圳)有限公司 Implementation method and device for information pushing
CN104253739A (en) * 2013-06-28 2014-12-31 中国移动通信集团公司 Implementing method, system and device of always online services

Family Cites Families (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103297461B (en) * 2012-02-28 2016-05-25 中国移动通信集团公司 NAT session keepalive duration method to set up and client and server
CN104427598B (en) * 2013-09-09 2018-02-23 中国移动通信集团公司 Exempt from the method and apparatus of heartbeat in line service for a long time
US10355963B2 (en) * 2014-10-29 2019-07-16 Huawei Technologies Co., Ltd. Heartbeat period setting method, and terminal
CN105897813A (en) * 2015-06-10 2016-08-24 乐视致新电子科技(天津)有限公司 Heartbeat message sending method, heartbeat message receiving method, heartbeat message sending device and heartbeat message receiving device
CN104991850B (en) * 2015-06-27 2018-06-19 广州华多网络科技有限公司 The heartbeat packet control method and device of a kind of application program
CN105871651A (en) * 2015-12-11 2016-08-17 乐视致新电子科技(天津)有限公司 Device connectivity monitoring method and device
CN106851799B (en) * 2017-01-19 2020-10-09 珠海市魅族科技有限公司 Method and device for sending heartbeat packet in long connection
CN109905259A (en) * 2017-12-08 2019-06-18 中国电信股份有限公司 Communicate to connect maintenance method, system and relevant device

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103491512A (en) * 2012-06-12 2014-01-01 腾讯科技(深圳)有限公司 Implementation method and device for information pushing
CN104253739A (en) * 2013-06-28 2014-12-31 中国移动通信集团公司 Implementing method, system and device of always online services

Also Published As

Publication number Publication date
CN110381130A (en) 2019-10-25

Similar Documents

Publication Publication Date Title
US10028226B2 (en) Efficient usage of internet services on mobile devices
RU2691640C2 (en) Method and apparatus for reducing energy consumption in mobile electronic device
US20190387475A1 (en) Power Management of a Mobile Communications Device
US10631361B2 (en) Method and apparatus for providing user with information received by electronic device
US9918138B2 (en) Method for controlling multimedia playing, apparatus thereof and storage medium
US9377839B2 (en) Dynamic battery management
EP2977854A1 (en) Method, apparatus, and user terminal for removing malicious power consuming application
EP3499353A1 (en) Apparatus and method for displaying notification in electronic device
EP3355223A1 (en) Unlock method and mobile terminal
CN103309756B (en) A kind of prevent application program from surprisingly exiting or to interrupt method and mobile terminal
EP2830044A1 (en) Instruction processing method, apparatus, and system
RU2686673C1 (en) Device and method of terminal control and terminal
KR20140043688A (en) Screen brightness control for mobile device
CN105786878B (en) Display method and device of browsing object
EP3294011A1 (en) Method and apparatus for wake-up control of intelligent terminal
US20140002396A1 (en) Information processing method, information processing apparatus and electronic device
US10762300B1 (en) Techniques to predictively respond to user requests using natural language processing
CN107992248B (en) Message display method and device
CN104899029A (en) Screen control method and apparatus
US20150332332A1 (en) Self-destructing ad messages in messaging apps
US20150130623A1 (en) Redirecting notifications to a wearable computing device
CN106776385B (en) A kind of transmission method, device and the terminal of log log information
US20150269164A1 (en) Electronic device and contact display method therefor
MX2015007250A (en) Gesture-based conversation processing method, apparatus, and terminal device.
US20100056209A1 (en) Mobile terminal and method for switching states thereof

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
PE01 Entry into force of the registration of the contract for pledge of patent right
PE01 Entry into force of the registration of the contract for pledge of patent right

Denomination of invention: Connection method, device, communication terminal and storage medium for keeping alive length

Effective date of registration: 20210126

Granted publication date: 20200529

Pledgee: Agricultural Bank of China Limited Changsha Yuhua District sub branch

Pledgor: HUNAN NEW CLOUDNET TECHNOLOGY Co.,Ltd.

Registration number: Y2021980000747