CN114585108A - Connection processing method and device - Google Patents

Connection processing method and device Download PDF

Info

Publication number
CN114585108A
CN114585108A CN202011293193.6A CN202011293193A CN114585108A CN 114585108 A CN114585108 A CN 114585108A CN 202011293193 A CN202011293193 A CN 202011293193A CN 114585108 A CN114585108 A CN 114585108A
Authority
CN
China
Prior art keywords
equipment
connection
heartbeat
screen state
acquiring
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202011293193.6A
Other languages
Chinese (zh)
Inventor
张耀
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Chengdu TD Tech Ltd
Original Assignee
Chengdu TD Tech 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 Chengdu TD Tech Ltd filed Critical Chengdu TD Tech Ltd
Priority to CN202011293193.6A priority Critical patent/CN114585108A/en
Publication of CN114585108A publication Critical patent/CN114585108A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04WWIRELESS COMMUNICATION NETWORKS
    • H04W76/00Connection management
    • H04W76/10Connection setup
    • H04W76/19Connection re-establishment
    • 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
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04WWIRELESS COMMUNICATION NETWORKS
    • H04W12/00Security arrangements; Authentication; Protecting privacy or anonymity
    • H04W12/06Authentication
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04WWIRELESS COMMUNICATION NETWORKS
    • H04W24/00Supervisory, monitoring or testing arrangements
    • H04W24/08Testing, supervising or monitoring using real traffic
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04WWIRELESS COMMUNICATION NETWORKS
    • H04W76/00Connection management
    • H04W76/10Connection setup
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04WWIRELESS COMMUNICATION NETWORKS
    • H04W76/00Connection management
    • H04W76/10Connection setup
    • H04W76/14Direct-mode setup
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D30/00Reducing energy consumption in communication networks
    • Y02D30/70Reducing energy consumption in communication networks in wireless communication networks

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Health & Medical Sciences (AREA)
  • Cardiology (AREA)
  • General Health & Medical Sciences (AREA)
  • Computer Security & Cryptography (AREA)
  • Mobile Radio Communication Systems (AREA)
  • Telephone Function (AREA)

Abstract

The invention provides a connection processing method and equipment, wherein the method comprises the following steps: after the connection with the second equipment is successful, acquiring the screen state of the first equipment, and determining the heartbeat cycle corresponding to the screen state; according to the heartbeat cycle corresponding to the screen state, the heartbeat packet is sent to the second equipment so as to keep the connection between the first equipment and the second equipment, so that the power consumption of the first equipment can be reduced, the problem that the power consumption is large because the first equipment needs to resend the heartbeat packet after receiving the response message is avoided, and meanwhile, the quantity of the heartbeat packets which need to be processed by the second equipment is correspondingly reduced because the quantity of the heartbeat packets which need to be sent by the first equipment is reduced, so that the load of the second equipment is reduced.

Description

Connection processing method and device
Technical Field
The embodiment of the invention relates to the technical field of terminals, in particular to a connection processing method and device.
Background
Some services (e.g., encryption services) within the secure mobile terminal need to initiate a heartbeat mechanism after a successful connection with its corresponding server, i.e., after a successful connection with the server, in order to maintain the connection between the secure mobile terminal and the server. At present, after a heartbeat mechanism is started, a safe mobile terminal sends a heartbeat packet to a server, and immediately resends the heartbeat packet after receiving a response message returned by the server.
However, after receiving the response message returned by the server, the secure mobile terminal needs to resend the heartbeat packet, so that the secure mobile terminal needs to frequently send the heartbeat packet to the server, and further, the power consumption of the secure mobile terminal is large.
Disclosure of Invention
The embodiment of the invention provides a connection processing method and equipment, which aim to solve the problem that a safe mobile terminal in the prior art is high in power consumption.
In a first aspect, an embodiment of the present invention provides a connection processing method, which is applied to a first device, and the method includes:
after the connection with the second equipment is successful, acquiring the screen state of the first equipment, and determining the heartbeat cycle corresponding to the screen state;
and sending a heartbeat packet to the second equipment according to a heartbeat period corresponding to the screen state so as to maintain the connection between the first equipment and the second equipment.
In one possible design, the determining a heartbeat cycle corresponding to the screen state includes:
if the screen state is the breath screen state, acquiring a heartbeat cycle corresponding to the breath screen state;
and if the screen state is the bright screen state, acquiring a heartbeat cycle corresponding to the bright screen state.
In one possible design, after the sending the heartbeat packet to the second device, the method further includes:
if the response message returned by the second equipment is not received within the first preset time, re-establishing connection with the second equipment and obtaining a connection result;
and if the connection result is connection failure, stopping sending the heartbeat packet to the second equipment.
In one possible design, after the sending the heartbeat packet to the second device, the method further includes:
if the response message returned by the second equipment is not received within the first preset time, acquiring the reconnection times;
if the reconnection times are greater than the preset times, stopping sending the heartbeat packet to the second equipment;
if the reconnection times are less than or equal to the preset times, re-establishing connection with the second equipment to obtain a connection result, and updating the reconnection times;
and if the connection result is connection failure, returning to the step of acquiring reconnection times.
In one possible design, the obtaining the screen status of the first device after the connection with the second device is successful includes:
after the connection with the second equipment is successful, sending user information to the second equipment so that the second equipment carries out authentication according to the user information to obtain an authentication result;
and acquiring the screen state of the first equipment according to the authentication result.
In one possible design, the obtaining the screen state of the first device according to the authentication result includes:
and if the authentication result comprises a secret key, acquiring the screen state of the first equipment.
In one possible design, the method further includes:
acquiring the network state of the first equipment;
and if the network state is the unavailable state, stopping sending the heartbeat packet to the second equipment.
In a second aspect, an embodiment of the present invention provides a connection processing apparatus, which is applied to a first apparatus, and includes:
the processing module is used for acquiring the screen state of the first equipment after the connection with the second equipment is successful, and determining the heartbeat cycle corresponding to the screen state;
and the transceiver module is used for sending a heartbeat packet to the second equipment according to a heartbeat cycle corresponding to the screen state so as to maintain the connection between the first equipment and the second equipment.
In one possible design, the processing module is further to:
if the screen state is the breath screen state, acquiring a heartbeat cycle corresponding to the breath screen state;
and if the screen state is the bright screen state, acquiring a heartbeat cycle corresponding to the bright screen state.
In one possible design, the transceiver module is further configured to:
after the heartbeat packet is sent to the second equipment, if a response message returned by the second equipment is not received within a first preset time, connection is established again with the second equipment, and a connection result is obtained;
and if the connection result is connection failure, stopping sending the heartbeat packet to the second equipment.
In one possible design, the transceiver module is further configured to:
after the heartbeat packet is sent to the second equipment, if a response message returned by the second equipment is not received within a first preset time, acquiring reconnection times;
if the reconnection times are greater than the preset times, stopping sending the heartbeat packet to the second equipment;
if the reconnection times are less than or equal to the preset times, re-establishing connection with the second equipment to obtain a connection result, and updating the reconnection times;
and if the connection result is connection failure, returning to the step of acquiring reconnection times.
In one possible design, the processing module is further to:
after the connection with the second equipment is successful, sending user information to the second equipment so that the second equipment carries out authentication according to the user information to obtain an authentication result;
and acquiring the screen state of the first equipment according to the authentication result.
In one possible design, the processing module is further to:
and if the authentication result comprises a secret key, acquiring the screen state of the first equipment.
In one possible design, the transceiver module is further configured to:
acquiring the network state of the first equipment;
and if the network state is the unavailable state, stopping sending the heartbeat packet to the second equipment.
In a third aspect, an embodiment of the present invention provides an electronic device, including: at least one processor and memory;
the memory stores computer-executable instructions;
the at least one processor executes computer-executable instructions stored by the memory to cause the at least one processor to perform the connection processing method as set forth in the first aspect above and in various possible designs of the first aspect.
In a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium, where computer-executable instructions are stored, and when a processor executes the computer-executable instructions, the connection processing method according to the first aspect and various possible designs of the first aspect is implemented.
The invention provides a connection processing method and equipment, which determine a heartbeat cycle according to the screen state of first equipment after successfully connecting with second equipment, namely the heartbeat cycle is related to the screen state of the first equipment, then send a heartbeat packet to the second equipment based on the heartbeat cycle, because the heartbeat cycle is related to the current screen state of the first equipment and is not of a fixed size, namely the time interval for sending the heartbeat packet is not fixed, the first equipment does not resend the heartbeat packet to the second equipment after receiving a response message returned by the second equipment, but sends the heartbeat packet to the second equipment based on the heartbeat cycle corresponding to the self state, so as to reduce the number of the heartbeat packets, thereby reducing the power consumption of the first equipment and avoiding the problem of larger power consumption caused by the fact that the first equipment resends the heartbeat packet after receiving the response message, meanwhile, the first device reduces the number of heartbeat packets to be sent, so that the number of heartbeat packets to be processed by the second device is correspondingly reduced, and the load of the second device is reduced.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings needed to be used in the description of the embodiments or the prior art will be briefly introduced below, and it is obvious that the drawings in the following description are some embodiments of the present invention, and for those skilled in the art, other drawings can be obtained according to these drawings without creative efforts.
Fig. 1 is a schematic diagram of a connection processing system according to an embodiment of the present invention;
fig. 2 is a first schematic flow chart of a connection processing method according to an embodiment of the present invention;
fig. 3 is a second flowchart illustrating a connection processing method according to an embodiment of the present invention;
fig. 4 is a schematic structural diagram of a connection processing device according to an embodiment of the present invention;
fig. 5 is a schematic diagram of a hardware structure of an electronic device according to an embodiment of the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are some, but not all, embodiments of the present invention. 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.
In the prior art, after some services (e.g., encryption services) in the secure mobile terminal are successfully connected with their corresponding servers, the services need to regularly keep null data interaction with the servers through the secure mobile terminal, that is, the secure mobile terminal needs to start a heartbeat mechanism to keep the connection between the secure mobile terminal and the servers. At present, after a heartbeat mechanism is started, a safe mobile terminal sends a heartbeat packet to a server, and immediately resends the heartbeat packet after receiving a response message returned by the server. However, after receiving the response message returned by the server, the secure mobile terminal needs to resend the heartbeat packet, so that the secure mobile terminal needs to frequently send the heartbeat packet to the server, and further, the power consumption of the secure mobile terminal is large.
Therefore, aiming at the problems, the technical idea of the invention is to start a heartbeat mechanism after the secure mobile terminal and the server socket are successfully established, namely after the secure mobile terminal and the server are successfully connected, and after the encryption service second-layer secret key is updated, determine a heartbeat cycle according to the screen state of the secure mobile terminal, send a heartbeat packet to the server according to the heartbeat cycle, and when the network of the secure mobile terminal is unavailable or continuously receives a response message sent by the remote server for a plurality of times within the preset time, reestablish the socket connection with the server, if the socket is established again and fails, stop sending the heartbeat packet to the server, so that the sending number of heartbeat packets can be effectively reduced, and the power consumption of the secure mobile terminal can be reduced.
The following describes the technical solutions of the present disclosure and how to solve the above technical problems in detail by specific examples. Several of these specific examples may be combined with each other below, and some of the same or similar concepts or processes may not be repeated in some examples. Examples of the present disclosure will now be described with reference to the accompanying drawings.
Fig. 1 is a schematic architecture diagram of a connection processing system according to an embodiment of the present invention, and as shown in fig. 1, the connection processing system includes a first device 101 and a second device 102, where the first device 101 sends a heartbeat packet to the second device after successfully connecting with the second device 102, and the second device returns a response message to the first device, so as to maintain a connection between the first device and the second device.
The first device 101 may be an electronic device such as a mobile terminal (e.g., a secure mobile terminal, a tablet, a computer, a wearable device, etc.), and the second device 102 may be an electronic device such as a server, a computer, etc.
Fig. 2 is a first flowchart illustrating a connection processing method according to an embodiment of the present invention, where an execution main body of the embodiment may be the first device in the embodiment shown in fig. 1. As shown in fig. 2, the method includes:
s201, after the connection with the second device is successful, the screen state of the first device is obtained, and the heartbeat cycle corresponding to the screen state is determined.
In this embodiment, in the running process of the service/application program in the first device, the service/application program needs to be connected with the second device, that is, long-distance connected, so that the service corresponding to the service/application program can be normally used, and therefore, after the service/application program in the first device is successfully connected with the second device, the service/application program needs to be connected with the second device long-distance based on the heartbeat mechanism, the heartbeat mechanism is started, that is, the current screen state of the first device is obtained, and a heartbeat cycle corresponding to the screen state is searched for sending a heartbeat packet by using the heartbeat cycle.
Wherein, when acquiring the current screen state of the first device, the current screen state can be acquired through a broadcast message. The screen state includes a screen-off state and a screen-on state. When a heartbeat mechanism is started, screen-off and screen-on broadcasts are registered, when the screen-off broadcasts are received, the current screen state of the first equipment is determined to be the screen-off state, and when the screen-on broadcasts are received, the current screen state of the first equipment is determined to be the screen-on state.
In any embodiment, optionally, if the screen state is the screenplay state, that is, when it is determined that the current state of the first device is the screenplay state, a heartbeat cycle corresponding to the screenplay state is obtained, where the heartbeat cycle is an initial heartbeat cycle, so that the heartbeat cycle is used to send a heartbeat packet. If the screen state is the bright screen state, namely when the current state of the first device is determined to be the breath screen state, acquiring a heartbeat cycle corresponding to the bright screen state, so as to send a heartbeat packet by using the heartbeat cycle.
Further, when the screen state of the first device is the screen resting state, it indicates that the user is not using the service/application, i.e. the number of interactions between the service/application and the second device is small, therefore, the heartbeat cycle can be set to be long, for example, set to 30 minutes, and correspondingly, the heartbeat packets are sent to the second device at a long interval, thereby reducing the number of heartbeat packets sent.
When the screen state of the first device is the bright screen state, it indicates that the user may use the service/application, i.e. the number of interactions between the service/application and the second device is large, so the heartbeat cycle may be set to be short, for example, to 15 minutes, and correspondingly, the heartbeat packet is sent to the second device at a short interval.
The service may be an encryption service, and the encryption service needs to be connected to the second device for a long time, so that the corresponding encryption-related services can be normally used. Correspondingly, the application program is an encryption application program, and the encryption application program needs to be in long connection with the second device, so that the corresponding encryption related services can be normally used.
S202, sending a heartbeat packet to the second equipment according to the heartbeat cycle corresponding to the screen state so as to keep the connection between the first equipment and the second equipment.
In this embodiment, after determining a heartbeat cycle corresponding to the screen state, based on the heartbeat cycle, a heartbeat packet is sent to the second device, so that the second device returns a corresponding response message after receiving the heartbeat packet, that is, a heartbeat response is sent to the first device, thereby maintaining a long connection between the first device and the second device.
Specifically, when the heartbeat packet is sent to the second device based on the heartbeat cycle corresponding to the screen state, one heartbeat packet is sent to the second device every other heartbeat cycle.
Optionally, when the heartbeat packet is sent to the second device based on the heartbeat period corresponding to the screen state, the heartbeat period may be set by a timer, for example, when the heartbeat period corresponding to the screen is 15 minutes, the timer is set for 15 minutes, that is, the heartbeat is triggered every 15 minutes.
In addition, optionally, in the process of sending the heartbeat packet to the second device based on the heartbeat cycle corresponding to the screen state, the broadcast related to the screen state may also be monitored based on the heartbeat cycle, that is, whether the screen-off broadcast and the screen-on broadcast exist is monitored every other heartbeat cycle, so as to determine the current screen state of the first device.
In addition, optionally, when the screen state continues to be the breath screen state within the second preset time, in order to reduce the power consumption of the first device, the heartbeat cycle corresponding to the breath screen state may be extended, that is, the initial heartbeat cycle corresponding to the breath screen state is changed to the target breath screen cycle.
The second preset time may be set according to actual conditions, for example, two initial heartbeat cycles may be set.
Taking a specific application scenario as an example, the initial heartbeat period corresponding to the breath screen state is 30 minutes, the target heartbeat period is 60 minutes, and the second preset time is 60 minutes, namely 60 minutes. And when the screen state is determined to be the screen-off state, sending a heartbeat packet to the second equipment every 30 minutes, simultaneously monitoring the broadcast of the screen-off and the broadcast of the screen-on, if the broadcast of the screen-on is not monitored within 60 minutes, namely determining that the first equipment is in the screen-off state within 60 minutes, setting the heartbeat period as a target heartbeat period, namely 60 minutes, and then sending the heartbeat packet to the second equipment every 60 minutes.
As can be seen from the above description, after the connection with the second device is successful, a heartbeat cycle is determined according to the screen state of the first device, that is, the heartbeat cycle is related to the screen state of the first device, and then a heartbeat packet is sent to the second device based on the heartbeat cycle, because the heartbeat cycle is related to the current screen state of the first device and is not of a fixed size, that is, the time interval for sending the heartbeat packet is not fixed, the first device does not resend the heartbeat packet to the second device after receiving a response message returned by the second device, but sends the heartbeat packet to the second device based on the heartbeat cycle corresponding to its own state, so as to reduce the number of heartbeat packets sent, thereby reducing the power consumption of the first device, and avoiding the problem that the power consumption is large because the first device needs to resend the heartbeat packet after receiving the response message, meanwhile, because the number of heartbeat packets sent by the first device is reduced, the number of heartbeat packets required to be processed by the second device is correspondingly reduced, and thus the load of the second device is reduced.
Fig. 3 is a second flowchart of a connection processing method according to an embodiment of the present invention, where on the basis of the embodiment of fig. 2, in order to reduce power consumption, after a first device is successfully connected to a second device, a heartbeat mechanism is not started immediately, but after the second device is successfully authenticated according to user information, the heartbeat mechanism is started, and this process will be described below with reference to a specific embodiment. As shown in fig. 3, the method includes:
s301, after the connection with the second device is successful, sending the user information to the second device so that the second device can perform authentication according to the user information to obtain an authentication result.
In this embodiment, after the first device and the second device are successfully connected, the first device obtains the user information and sends the user information to the second device, and the second device authenticates the user information, that is, determines whether the user information is correct, and obtains a corresponding authentication result, that is, when it is determined that the user information is correct, indicating that the authentication is successful, the second device obtains a key corresponding to the user information and generates an authentication result according to the key, that is, the authentication result includes the key. When it is determined that the user information is incorrect, indicating that authentication has failed, the authentication result is made to include authentication failure. After obtaining the authentication result, the second device sends the authentication result to the first device, so that the first device determines whether a heartbeat mechanism needs to be started, that is, determines whether a heartbeat packet is sent to the second device.
Optionally, the user information may be information of a registered user corresponding to the service/application on the first device, and specifically, may be related user registration information in the encrypted service. The user information includes at least one of a user account, a user password, and a user identifier.
When determining whether the user information is correct, the second device may determine whether the pre-stored user information identical to the user information exists in the pre-stored user information, for example, when the user information only includes a user account, the second device determines whether the user account exists, that is, whether the pre-stored user information identical to the user account is pre-stored, and if the user information exists, determines that the user information is correct.
It can be understood that, when data transmission is performed on a service related to an encryption service or an encryption application on the secure mobile terminal, encryption needs to be performed by using a key, so that the server returns the corresponding key to the secure mobile terminal after determining that the user information is correct.
S302, obtaining an authentication result sent by the second device, and obtaining the screen state of the first device according to the authentication result.
In this embodiment, after receiving the authentication result sent by the second device, it is determined whether to acquire the screen state of the first device according to the authentication result, so as to determine whether to start the heartbeat mechanism.
Optionally, if the authentication result includes the key, which indicates that the user authentication is successful, that is, the service/application authentication is successful, the screen state of the first device is obtained. And if the authentication result is authentication failure, the user authentication is successful, namely the service/application authentication fails, and the screen state of the first device is not acquired without starting a heartbeat mechanism.
In addition, optionally, after the user information is sent to the second device, if a flag that the updating of the second-layer key returned by the remote server is completed, that is, the key, is received, a new thread is started, a heartbeat is sent to register in the remote server, and then a heartbeat cycle is started, that is, a heartbeat mechanism is started.
And S303, sending a heartbeat packet to the second equipment according to the heartbeat cycle corresponding to the screen state so as to keep the connection between the first equipment and the second equipment.
In this embodiment, after the heartbeat packet is sent to the second device, if a response message returned by the second device is not received within a first preset time, connection is established again with the second device, and a connection result is obtained; and if the connection result is connection failure, stopping sending the heartbeat packet to the second equipment.
Specifically, after the heartbeat packet is sent to the second device, if a response message corresponding to the heartbeat packet sent by the second device is not received within a first preset time, that is, when a heartbeat response is sent, it is indicated that the second device may have a problem, and a long connection between the second device and the first device may have been disconnected, connection is re-established with the second device, that is, a socket with the second device is re-established, and a corresponding connection result is obtained, where the connection result includes a connection success and a connection failure.
And when the connection result is that the connection is successful, indicating that the connection with the second device is successful, returning to the step of acquiring the screen state of the first device, namely sending the heartbeat packet to the second device based on the heartbeat cycle corresponding to the current screen state of the first device.
When the connection result is a connection failure, it indicates that the connection with the second device has failed, and the second device may have a problem, so that the second device cannot perform communication connection with the first device.
The first preset time may be set according to actual conditions, for example, the first preset time is 90 seconds, and is not limited herein.
Further, optionally, after the heartbeat packet is sent to the second device, if a response message returned by the second device is not received within the first preset time, the reconnection times are obtained. And if the reconnection times are greater than the preset times, stopping sending the heartbeat packet to the second equipment. And if the reconnection times are less than or equal to the preset times, re-establishing connection with the second equipment to obtain a connection result, and updating the reconnection times. And if the connection result is connection failure, returning to the step of acquiring reconnection times.
Specifically, after the heartbeat packet is sent to the second device, if a response message corresponding to the heartbeat packet sent by the second device is not received within a first preset time, that is, when a heartbeat response is sent, it is indicated that the second device may have a problem, and a long connection between the second device and the first device may have been disconnected, a reconnection number is obtained, where the reconnection number indicates a number of times that the first device and the second device reestablish a connection after the heartbeat mechanism is started, and an initial value of the reconnection number is 0.
When the reconnection number is determined to be greater than the preset number, it indicates that the number of times that the first device reestablishes the connection at the first device is large, and the second device may have a problem and cannot be connected and communicated with the first device.
When the reconnection times are determined to be less than or equal to the preset times, the number of times that the first device reestablishes connection at the first device is low, connection can be tried again, the reconnection times are updated, namely 1 is added to the reconnection times, connection with the second device is reestablished, when the connection result is that the connection is successful, the connection between the first device and the second device is successful, the heartbeat packet can be continuously sent to the second device, when the connection result is that the connection is failed, the reconnection between the first device and the second device is failed, the step of obtaining the reconnection times is returned to, whether the connection with the second device needs to be reestablished is determined, namely, whether the second device has problems is determined, and whether the heartbeat packet needs to be stopped being sent to the second device is determined.
The preset number may be set according to actual conditions, for example, the preset number is 2, and is not limited herein.
Taking a specific application scenario as an example, the preset number of times is 2, the initial value of the reconnection number of times is 0, after sending the heartbeat packet to the second device, if a response message returned by the second device is not received within a first preset time, the current reconnection number of times is obtained to be 0, which is less than 2, the reconnection number of times is added with 1, and connection is reestablished with the second device, when the connection result is that the connection fails, the current reconnection number of times is obtained to be 1, which is still less than 2, the reconnection number of times is added with 1, and connection is reestablished with the second device, and when the connection result is that the connection fails, the current reconnection number of times is obtained to be 2, which is not less than 2, so that connection with the second device does not need to be reestablished, and the heartbeat packet is stopped being sent to the second device.
In this embodiment, after sending the heartbeat packet to the second device, if the heartbeat response returned by the second device is not received within the first preset time, the first device may perform multiple reconnection, and when the connection results corresponding to the multiple reconnection are all connection failures, it indicates that the second device has a problem/abnormality, and does not need to keep long connection with the second device any more, but does not consider that the second device has a problem and does not keep long connection with the second device after performing one reconnection failure, so as to avoid that the second device does not succeed in reconnection with the first device due to some reasons (for example, the second device does not receive a reconnection request sent by the first device), but the second device does not actually have a problem at this time, thereby causing misjudgment of the first device.
In any embodiment, optionally, after the heartbeat mechanism is started, i.e. during the process of maintaining a long connection with the second device, the network status of the first device may be acquired in real time or at certain intervals. And if the network state is the unavailable state, stopping sending the heartbeat packet to the second equipment.
Specifically, the network status includes an available status and an unavailable status, and when the network status is the available status, it indicates that the network of the first device is available; when the network state is the unavailable state, the network of the first device is indicated to be unavailable, when the network is unavailable, the maintenance of the long connection is unnecessary, and then the heartbeat mechanism is directly terminated, namely the heartbeat packet is stopped from being sent to the second device, so that the power consumption of the first device is reduced.
In this embodiment, when the first device determines that its own network is unavailable or cannot be in communication connection with the second device, that is, when the second device is abnormal, it indicates that it is not necessary to maintain the connection between the first device and the second device, and directly stops sending the heartbeat packet to the second device, thereby reducing the power consumption of the first device.
In this embodiment, after the connection with the second device is successful, the user information is sent to the second device first to perform user authentication, that is, the heartbeat mechanism is started only after the encryption authentication of the service/application program is successful, instead of starting the heartbeat mechanism after the connection with the second device is successful, thereby avoiding performing unnecessary heartbeat due to the failure of the user authentication, and further reducing the power consumption of the first device.
Fig. 4 is a schematic structural diagram of a connection processing device according to an embodiment of the present invention. The connection processing apparatus is applied to a first apparatus, and as shown in fig. 4, the connection processing apparatus 40 includes: a processing module 401 and a transceiver module 402.
The processing module 401 is configured to, after the connection with the second device is successful, obtain a screen state of the first device, and determine a heartbeat cycle corresponding to the screen state.
A transceiver module 402, configured to send a heartbeat packet to the second device according to a heartbeat cycle corresponding to the screen state to maintain a connection between the first device and the second device.
In one possible design, the processing module 401 is further configured to:
and if the screen state is the breath screen state, acquiring a heartbeat cycle corresponding to the breath screen state.
And if the screen state is the bright screen state, acquiring a heartbeat cycle corresponding to the bright screen state.
In one possible design, transceiver module 402 is further configured to:
after the heartbeat packet is sent to the second device, if a response message returned by the second device is not received within the first preset time, connection is established again with the second device, and a connection result is obtained.
And if the connection result is connection failure, stopping sending the heartbeat packet to the second equipment.
In one possible design, transceiver module 402 is further configured to:
after the heartbeat packet is sent to the second device, if a response message returned by the second device is not received within a first preset time, the reconnection times are obtained.
And if the reconnection times are greater than the preset times, stopping sending the heartbeat packet to the second equipment.
And if the reconnection times are less than or equal to the preset times, re-establishing connection with the second equipment to obtain a connection result, and updating the reconnection times.
And if the connection result is connection failure, returning to the step of acquiring the reconnection times.
In one possible design, the processing module 401 is further configured to:
and after the connection with the second equipment is successful, sending the user information to the second equipment so that the second equipment carries out authentication according to the user information to obtain an authentication result.
And acquiring the screen state of the first equipment according to the authentication result.
In one possible design, the processing module 401 is further configured to:
and if the authentication result comprises the secret key, acquiring the screen state of the first equipment.
In one possible design, transceiver module 402 is further configured to:
the network state of the first device is obtained.
And if the network state is the unavailable state, stopping sending the heartbeat packet to the second equipment.
The connection processing device provided in the embodiment of the present invention can implement the connection processing method in the above-described embodiment, and the implementation principle and technical effect are similar, which are not described herein again.
Fig. 5 is a schematic diagram of a hardware structure of an electronic device according to an embodiment of the present invention. As shown in fig. 5, the electronic apparatus 50 of the present embodiment includes: a processor 501 and a memory 502; wherein
A memory 502 for storing computer-executable instructions;
the processor 501 is configured to execute computer-executable instructions stored in the memory to implement the steps performed by the receiving device in the above embodiments. Reference may be made in particular to the description relating to the method embodiments described above.
Alternatively, the memory 502 may be separate or integrated with the processor 501.
When the memory 502 is provided separately, the electronic device further comprises a bus 503 for connecting said memory 502 and the processor 501.
An embodiment of the present invention further provides a computer-readable storage medium, where a computer execution instruction is stored in the computer-readable storage medium, and when a processor executes the computer execution instruction, the connection processing method is implemented as above.
In the embodiments provided in the present invention, it should be understood that the disclosed apparatus and method may be implemented in other ways. For example, the above-described device embodiments are merely illustrative, and for example, the division of the modules is only one logical division, and other divisions may be realized in practice, for example, a plurality of modules 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 modules, and may be in an electrical, mechanical or other form.
The modules described as separate parts may or may not be physically separate, and parts displayed as modules 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 modules may be selected according to actual needs to achieve the purpose of the solution of the present embodiment.
In addition, functional modules in the embodiments of the present invention may be integrated into one processing unit, or each module may exist alone physically, or two or more modules are integrated into one unit. The unit formed by the modules can be realized in a hardware mode, and can also be realized in a mode of hardware and a software functional unit.
The integrated module implemented in the form of a software functional module may be stored in a computer-readable storage medium. The software functional module is stored in a storage medium and includes several instructions for enabling a computer device (which may be a personal computer, a server, or a network device) or a processor (processor) to execute some steps of the methods according to the embodiments of the present application.
It should be understood that the Processor may be a Central Processing Unit (CPU), other general purpose Processor, a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), etc. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like. The steps of a method disclosed in connection with the present invention may be embodied directly in a hardware processor, or in a combination of the hardware and software modules within the processor.
The memory may comprise a high-speed RAM memory, and may further comprise a non-volatile storage NVM, such as at least one disk memory, and may also be a usb disk, a removable hard disk, a read-only memory, a magnetic or optical disk, etc.
The bus may be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, an Extended ISA (EISA) bus, or the like. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of illustration, the buses in the figures of the present application are not limited to only one bus or one type of bus.
The storage medium may be implemented by any type or combination of volatile or non-volatile memory devices, such as Static Random Access Memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic or optical disks. A storage media may be any available media that can be accessed by a general purpose or special purpose computer.
An exemplary storage medium is coupled to the processor such the processor can read information from, and write information to, the storage medium. Of course, the storage medium may also be integral to the processor. The processor and the storage medium may reside in an Application Specific Integrated Circuits (ASIC). Of course, the processor and the storage medium may reside as discrete components in an electronic device or host device.
Those of ordinary skill in the art will understand that: all or a portion of the steps of implementing the above-described method embodiments may be performed by hardware associated with program instructions. The program may be stored in a computer-readable storage medium. When executed, the program performs steps comprising the method embodiments described above; and the aforementioned storage medium includes: various media that can store program codes, such as ROM, RAM, magnetic or optical disks.
Finally, it should be noted that: the above embodiments are only used to illustrate the technical solution of the present invention, and not to limit the same; while the invention has been described in detail and with reference to the foregoing embodiments, it will be understood by those skilled in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some or all of the technical features may be equivalently replaced; and the modifications or the substitutions do not make the essence of the corresponding technical solutions depart from the scope of the technical solutions of the embodiments of the present invention.

Claims (10)

1. A connection processing method applied to a first device, the method comprising:
after the connection with the second equipment is successful, acquiring the screen state of the first equipment, and determining the heartbeat cycle corresponding to the screen state;
and sending a heartbeat packet to the second equipment according to a heartbeat period corresponding to the screen state so as to maintain the connection between the first equipment and the second equipment.
2. The method of claim 1, wherein the determining a heartbeat cycle corresponding to the screen state comprises:
if the screen state is the breath screen state, acquiring a heartbeat cycle corresponding to the breath screen state;
and if the screen state is the bright screen state, acquiring a heartbeat cycle corresponding to the bright screen state.
3. The method according to claim 1 or 2, further comprising, after the sending the heartbeat packet to the second device:
if the response message returned by the second equipment is not received within the first preset time, re-establishing connection with the second equipment and obtaining a connection result;
and if the connection result is connection failure, stopping sending the heartbeat packet to the second equipment.
4. The method according to claim 1 or 2, wherein after said sending the heartbeat packet to the second device, further comprising:
if the response message returned by the second equipment is not received within the first preset time, acquiring the reconnection times;
if the reconnection times are greater than the preset times, stopping sending the heartbeat packet to the second equipment;
if the reconnection times are less than or equal to the preset times, re-establishing connection with the second equipment to obtain a connection result, and updating the reconnection times;
and if the connection result is connection failure, returning to the step of acquiring reconnection times.
5. The method of claim 1, wherein obtaining the screen status of the first device after the connection with the second device is successful comprises:
after the connection with the second equipment is successful, sending user information to the second equipment so that the second equipment carries out authentication according to the user information to obtain an authentication result;
and acquiring an authentication result sent by the second equipment, and acquiring the screen state of the first equipment according to the authentication result.
6. The method of claim 5, wherein obtaining the screen status of the first device according to the authentication result comprises:
and if the authentication result comprises the secret key, acquiring the screen state of the first equipment.
7. The method according to claim 1 or 2, characterized in that the method further comprises:
acquiring the network state of the first equipment;
and if the network state is the unavailable state, stopping sending the heartbeat packet to the second equipment.
8. A connection processing device, applied to a first device, the device comprising:
the processing module is used for acquiring the screen state of the first equipment after the second equipment is successfully connected and determining the heartbeat cycle corresponding to the screen state;
and the transceiver module is used for sending a heartbeat packet to the second equipment according to a heartbeat cycle corresponding to the screen state so as to maintain the connection between the first equipment and the second equipment.
9. An electronic device, comprising: at least one processor and memory;
the memory stores computer execution instructions;
the at least one processor executing the computer-executable instructions stored by the memory causes the at least one processor to perform the connection processing method of any of claims 1 to 7.
10. A computer-readable storage medium having stored thereon computer-executable instructions which, when executed by a processor, implement the connection processing method according to any one of claims 1 to 7.
CN202011293193.6A 2020-11-18 2020-11-18 Connection processing method and device Pending CN114585108A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202011293193.6A CN114585108A (en) 2020-11-18 2020-11-18 Connection processing method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202011293193.6A CN114585108A (en) 2020-11-18 2020-11-18 Connection processing method and device

Publications (1)

Publication Number Publication Date
CN114585108A true CN114585108A (en) 2022-06-03

Family

ID=81768430

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202011293193.6A Pending CN114585108A (en) 2020-11-18 2020-11-18 Connection processing method and device

Country Status (1)

Country Link
CN (1) CN114585108A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115499902A (en) * 2022-08-16 2022-12-20 广州汽车集团股份有限公司 Long connection holding method, device, vehicle, server and storage medium

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105608347A (en) * 2015-07-29 2016-05-25 宇龙计算机通信科技(深圳)有限公司 Operation system switching method, operation system switching device and terminal
CN105610913A (en) * 2015-12-22 2016-05-25 用友网络科技股份有限公司 Heartbeat keep-alive method and apparatus for long connection in communication network
CN107736000A (en) * 2015-06-30 2018-02-23 华为技术有限公司 The method and terminal that a kind of terminal interacts with the network equipment
CN110381130A (en) * 2019-07-12 2019-10-25 湖南新云网科技有限公司 The long connection method of keep-alive, device, communication terminal and storage medium
CN110474975A (en) * 2019-08-08 2019-11-19 北京云中融信网络科技有限公司 Heartbeat processing method, device, electronic equipment and the storage medium of application program
CN111510492A (en) * 2020-04-15 2020-08-07 矩阵元技术(深圳)有限公司 Data processing method, device, equipment and system for realizing disconnection reconnection

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107736000A (en) * 2015-06-30 2018-02-23 华为技术有限公司 The method and terminal that a kind of terminal interacts with the network equipment
CN105608347A (en) * 2015-07-29 2016-05-25 宇龙计算机通信科技(深圳)有限公司 Operation system switching method, operation system switching device and terminal
CN105610913A (en) * 2015-12-22 2016-05-25 用友网络科技股份有限公司 Heartbeat keep-alive method and apparatus for long connection in communication network
CN110381130A (en) * 2019-07-12 2019-10-25 湖南新云网科技有限公司 The long connection method of keep-alive, device, communication terminal and storage medium
CN110474975A (en) * 2019-08-08 2019-11-19 北京云中融信网络科技有限公司 Heartbeat processing method, device, electronic equipment and the storage medium of application program
CN111510492A (en) * 2020-04-15 2020-08-07 矩阵元技术(深圳)有限公司 Data processing method, device, equipment and system for realizing disconnection reconnection

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115499902A (en) * 2022-08-16 2022-12-20 广州汽车集团股份有限公司 Long connection holding method, device, vehicle, server and storage medium

Similar Documents

Publication Publication Date Title
CN109905312B (en) Message pushing method, device and system
US9883386B2 (en) Method and a server for managing profiles
CN113315684B (en) Communication management method and device, electronic equipment and storage medium
CN111343156B (en) Registration authentication method, server, terminal device and readable storage medium
US20170134384A1 (en) Method and device for obtaining superuser permission
CN109982065B (en) Method, device and storage medium for equipment fault recovery in video monitoring network
CN114268565A (en) Terminal device, heartbeat packet transmission interval detection method thereof and storage medium
CN112383402A (en) Dual idempotent verification method and server
CN114585108A (en) Connection processing method and device
CN110445932B (en) Abnormal card dropping processing method and device, storage medium and terminal
CN111522571B (en) Equipment upgrading method and device, terminal equipment and storage medium
CN111654451B (en) Message anti-replay method and electronic equipment
CN111371598A (en) Configuration method and system
CN113117318B (en) Multi-platform data intercommunication realization method and device, computer equipment and storage medium
WO2020102940A1 (en) Abnormality processing method, terminal device and storage medium
CN113412480A (en) Mounting processing method and device, electronic equipment and computer readable storage medium
CN111131198B (en) Updating method and device for network security policy configuration
CN112328422A (en) Abnormity repairing method and device, electronic equipment and storage medium
CN112769889B (en) Service data pushing method and device, storage medium and electronic device
CN110851328A (en) Method for detecting abnormal power failure of password card in PKCS #11 application
CN111124445A (en) Home gateway upgrading method and home gateway
CN115037601B (en) Network recovery method, system, medium and electronic device for vehicle-mounted network interface device
CN114006935B (en) Private network terminal network access method, device and equipment
US11916910B1 (en) Remedying wireless-network connection failures
CN111327722B (en) Conflict detection method, system, terminal and storage medium for static IP and dynamic IP

Legal Events

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

Application publication date: 20220603