CN110881224A - Network long connection method, device, equipment and storage medium - Google Patents
Network long connection method, device, equipment and storage medium Download PDFInfo
- Publication number
- CN110881224A CN110881224A CN201811039057.7A CN201811039057A CN110881224A CN 110881224 A CN110881224 A CN 110881224A CN 201811039057 A CN201811039057 A CN 201811039057A CN 110881224 A CN110881224 A CN 110881224A
- Authority
- CN
- China
- Prior art keywords
- reconnection
- target application
- application program
- disconnection
- long connection
- 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.)
- Granted
Links
Images
Classifications
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04W—WIRELESS COMMUNICATION NETWORKS
- H04W76/00—Connection management
- H04W76/10—Connection setup
- H04W76/19—Connection re-establishment
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L67/00—Network arrangements or protocols for supporting network services or applications
- H04L67/14—Session management
- H04L67/141—Setup of application sessions
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04W—WIRELESS COMMUNICATION NETWORKS
- H04W76/00—Connection management
- H04W76/10—Connection setup
Abstract
The embodiment of the invention discloses a network long connection method, a device, equipment and a storage medium. The method comprises the following steps: when detecting that the target application program meets the long connection reconnection condition, acquiring a packaging object corresponding to the target application program; acquiring reconnection parameters of encapsulation in an encapsulation object; the reconnection parameters include: enabling attribute of disconnection reconnection function and disconnection reconnection interval time; and if the disconnection reconnection function enabling attribute is determined to be the disconnection reconnection function, performing reconnection operation on the target application program according to the disconnection reconnection interval time and the thread type of the target application program for disconnecting the long connection.
Description
Technical Field
The present invention relates to computer technologies, and in particular, to a method, an apparatus, a device, and a storage medium for long connection of a network.
Background
The long connection means that a plurality of data packets can be continuously sent on one connection, and is mostly used in a communication scene with frequent operation, point-to-point and a small number of connections, for example, a mobile phone push service, in which a connection link between a mobile phone client and a server is established in advance, and when a message needs to be sent to a mobile phone, the message can be directly sent through the link.
In the case of using a long connection, after a web page is opened, the TCP connection for transmitting HTTP data between the client and the server is not closed, and the client continues to use the established connection when accessing the server again.
The inventor finds that retry is carried out continuously after disconnection, performance waste is caused, and congestion and ANR abnormity of a main thread are caused.
Disclosure of Invention
Embodiments of the present invention provide a method, an apparatus, a device, and a storage medium for long network connection, so as to avoid situations of congestion of a main thread, ANR abnormality, and performance waste.
In a first aspect, an embodiment of the present invention provides a network long connection method, including:
when detecting that a target application program meets a long connection reconnection condition, acquiring a packaging object corresponding to the target application program;
obtaining reconnection parameters of the package in the package object; the reconnection parameters include: enabling attribute of disconnection reconnection function and disconnection reconnection interval time;
and if the disconnection reconnection function enabling attribute is determined to be the disconnection reconnection function, performing reconnection operation on the target application program according to the disconnection reconnection interval time and the thread type of the target application program for disconnecting the long connection.
Further, according to the interval time of the disconnection reconnection and the thread type of the target application program for disconnecting the long connection, the performing of the reconnection operation on the target application program includes:
if the thread type of the target application program disconnected with the long connection is determined to be the main thread of the target application program, immediately executing reconnection operation on the target application program;
and if the thread type of the target application program disconnected with the long connection is determined to be the non-main thread of the application program, the reconnection operation on the target application program is executed according to the interval time of disconnection reconnection.
Further, the reconnection parameters further include: the number of reconnection times;
if the disconnection reconnection function enabling attribute is determined to be the disconnection reconnection function, performing reconnection operation on the target application program according to the disconnection reconnection interval time and the thread type of the target application program for disconnecting the long connection, specifically comprising:
if the disconnection reconnection function enabling attribute is determined to be the disconnection reconnection function, and the currently recorded total disconnection reconnection times do not exceed the disconnection reconnection times in the reconnection parameters, then according to the disconnection reconnection interval time and the thread type of the target application program for disconnecting long connection, the reconnection operation on the target application program is executed;
after the reconnection operation on the target application program is executed according to the interval time of disconnection reconnection and the thread type of disconnection of the target application program, the method further comprises the following steps:
and updating the total disconnection reconnection times of the current record.
Further, when it is detected that the target application program satisfies the long connection reconnection condition, before obtaining the encapsulation object corresponding to the target application program, the method further includes:
a database about the corresponding relation between the application program and the packaging object is established in advance;
when detecting that the target application program meets the long connection reconnection condition, acquiring reconnection parameters packaged in the packaged object, wherein the reconnection parameters comprise:
and when detecting that the target application program meets the long connection reconnection condition, searching the database to obtain a packaging object which is packaged with reconnection parameters and corresponds to the target application program.
Further, when it is detected that the target application program satisfies the long connection reconnection condition, before obtaining the encapsulation object corresponding to the target application program, the method further includes:
establishing websocket long connection communication through the okhttp;
using a subscriber of rxjava to monitor a callback function;
and if the callback function is a preset function, determining that the target application program meets the long connection reconnection condition.
Further, the preset function is an oneerror method.
Further, before obtaining the reconnection parameters encapsulated in the encapsulated object, the method further includes:
and obtaining the encapsulated object by using the rxjava encapsulation reconnection parameter.
In a second aspect, an embodiment of the present invention further provides a network long connection device, where the device includes:
the device comprises a first acquisition module, a second acquisition module and a third acquisition module, wherein the first acquisition module is used for acquiring a packaging object corresponding to a target application program when the target application program is detected to meet a long connection reconnection condition;
a second obtaining module, configured to obtain reconnection parameters encapsulated in the encapsulated object; the reconnection parameters include: enabling attribute of disconnection reconnection function and disconnection reconnection interval time;
and the execution module is used for executing reconnection operation on the target application program according to the interval time of disconnection reconnection and the thread type of disconnection of the target application program.
Further, the execution module is specifically configured to:
if the thread type of the target application program disconnected with the long connection is determined to be the main thread of the target application program, immediately executing reconnection operation on the target application program;
and if the thread type of the target application program disconnected with the long connection is determined to be the non-main thread of the application program, the reconnection operation on the target application program is executed according to the interval time of disconnection reconnection.
Further, the reconnection parameters further include: the number of reconnection times;
the execution module comprises:
a reconnection operation executing unit, configured to, if it is determined that the disconnection reconnection function enabling attribute is to start a disconnection reconnection function and the currently recorded total number of disconnection reconnection times does not exceed the number of disconnection reconnection times in the reconnection parameter, execute a reconnection operation on the target application program according to the interval time of the disconnection reconnection and the thread type of the target application program for disconnecting the long connection;
further comprising:
and the updating unit is used for updating the total times of disconnection reconnection of the current record.
Further, the method also comprises the following steps:
the system comprises an establishing module, a packaging module and a processing module, wherein the establishing module is used for establishing a database of the corresponding relation between an application program and a packaging object in advance;
the first obtaining module is specifically configured to:
and when detecting that the target application program meets the long connection reconnection condition, searching the database to obtain a packaging object which is packaged with reconnection parameters and corresponds to the target application program.
In a third aspect, an embodiment of the present invention further provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, where the processor executes the computer program to implement the network long connection method according to any one of the embodiments of the present invention.
In a fourth aspect, the embodiment of the present invention further provides a computer-readable storage medium, on which a computer program is stored, where the computer program, when executed by a processor, implements the network long connection method according to any one of the embodiments of the present invention.
According to the embodiment of the invention, when the target application program is detected to meet the long connection reconnection condition, a packaging object corresponding to the target application program is obtained; obtaining reconnection parameters of the package in the package object; the reconnection parameters include: enabling attribute of disconnection reconnection function and disconnection reconnection interval time; and if the disconnection reconnection function enabling attribute is determined to be the disconnection reconnection function, performing reconnection operation on the target application program according to the disconnection reconnection interval time and the thread type of the target application program for disconnecting the long connection so as to avoid the situations of main thread congestion, ANR abnormity and performance waste.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings needed to be used in the embodiments will be briefly described below, it should be understood that the following drawings only illustrate some embodiments of the present invention and therefore should not be considered as limiting the scope, and for those skilled in the art, other related drawings can be obtained according to the drawings without inventive efforts.
Fig. 1 is a flowchart of a network long connection method according to a first embodiment of the present invention;
fig. 2 is a flowchart of a network long connection method according to a second embodiment of the present invention;
fig. 3 is a schematic structural diagram of a network long connection device according to a third embodiment of the present invention;
fig. 4 is a schematic structural diagram of a computer device in the fourth embodiment of the present invention.
Detailed Description
The present invention will be described in further detail with reference to the accompanying drawings and examples. It is to be understood that the specific embodiments described herein are merely illustrative of the invention and are not limiting of the invention. It should be further noted that, for the convenience of description, only some of the structures related to the present invention are shown in the drawings, not all of the structures.
It should be noted that: like reference numbers and letters refer to like items in the following figures, and thus, once an item is defined in one figure, it need not be further defined and explained in subsequent figures. Meanwhile, in the description of the present invention, the terms "first", "second", and the like are used only for distinguishing the description, and are not to be construed as indicating or implying relative importance.
Example one
Fig. 1 is a flowchart of a network long connection method according to an embodiment of the present invention, where the present embodiment is applicable to a network long connection situation, and the method may be executed by a network long connection device according to an embodiment of the present invention, where the device may be implemented in a software and/or hardware manner, as shown in fig. 1, the method specifically includes the following steps:
s110, when the target application program is detected to meet the long connection reconnection condition, acquiring a packaging object corresponding to the target application program.
And the long connection reconnection condition is that the target application program is in a disconnected long connection state at present and needs to be subjected to long connection reconnection. It should be noted that, when the target application changes from the normal connection state to the disconnection long connection state, the target application satisfies the long connection reconnection condition, the target application continues to be in the disconnection long connection state, and the target application also satisfies the long connection reconnection condition. For example, if the target application does not initially perform long-connection communication successfully, and needs to perform reconnection at this time, the target application may satisfy the long-connection reconnection condition. If the target application program is in a normal connection state and becomes a disconnection long connection state for some reason, the target application program meets the long connection reconnection condition.
The determination method of the target application program in the abnormal state is as follows: when the target application program is in the disconnection long connection state, the system calls back a connection abnormal function, and then the target application program is determined to be in the disconnection long connection state. If the system calls back a normal connection function, determining that the target application program is in a normal connection state, for example, creating websocket long connection communication through okhttp; using an rxjava subscriber to subscribe a callback function related to long connection, if the long connection callback function calls an oneerror method, the long connection state of the target application program is a disconnected long connection state, and if the onMessageReiceve method is called, the long connection state of the target application program is a normal connection state. oneror and onmessageReicee are callback functions provided by okhttp, and are used for giving the caller the knowledge of whether long-connection communication is successful or failed and whether a message arrives.
Specifically, if the target application program is determined to be in a disconnected long connection state by monitoring the long connection callback function, the target application program is determined to meet a long connection reconnection condition, and a package object corresponding to the target application program is acquired.
Optionally, when it is detected that the target application satisfies the long connection reconnection condition, before obtaining the encapsulation object corresponding to the target application, the method further includes:
a database regarding correspondence of the application program and the package object is established in advance.
The database includes a corresponding relationship between the application program and the package object, for example, if the application program a corresponds to the package object a and the application program B corresponds to the package object B, different reconnection parameters are set for different application programs.
Specifically, a database of a correspondence relationship between the application program and the package is established in advance, and for example, the database may include: the application program a corresponds to the package object a, the application program B corresponds to the package object B, the application program C corresponds to the package object C, or the application program C corresponds to the package object a.
When detecting that the target application program meets the long connection reconnection condition, acquiring reconnection parameters packaged in the packaged object, wherein the reconnection parameters comprise:
and when detecting that the target application program meets the long connection reconnection condition, searching the database to obtain a packaging object which is packaged with reconnection parameters and corresponds to the target application program.
Specifically, when it is detected that the target application satisfies the long connection reconnection condition, a pre-established database is searched for and a package object corresponding to the target application is obtained, for example, the database may include: and if the target application program is the application program A, querying the database to obtain that the packaging object which is packaged with reconnection parameters and corresponds to the target application program is the packaging object A.
S120, obtaining reconnection parameters of the package in the package object; the reconnection parameters include: the disconnection reconnect function enables attributes and the interval time of disconnection reconnect.
Wherein the disconnection reconnecting function enabling attribute includes: and starting a disconnection reconnection function and closing the disconnection reconnection function.
The interval time of the disconnection reconnection may be set according to a user requirement, or may be set by a system, which is not limited in the embodiment of the present invention.
And the packaging object is a class packaged with reconnection parameters.
Specifically, the disconnection reconnection function enabling attribute of the package in the package object and the disconnection reconnection interval time are obtained.
And S130, if the disconnection reconnection function enabling attribute is determined to be the disconnection reconnection function, performing reconnection operation on the target application program according to the disconnection reconnection interval time and the thread type of the target application program for disconnecting the long connection.
Wherein the thread type of the target application program for disconnecting the long connection comprises the following steps: a main thread and a non-main thread.
Specifically, if the disconnection reconnection function enabling attribute of the package in the package object is acquired as the disconnection reconnection function, the reconnection operation on the target application program is executed according to the disconnection reconnection interval time of the package in the package object and the thread type of the target application program for disconnecting the long connection.
Optionally, if it is determined that the disconnection reconnection function enabling attribute is to close the disconnection reconnection function, disconnection reconnection is not performed.
According to the technical scheme of the embodiment of the invention, when the target application program is detected to meet the long connection reconnection condition, the encapsulation object corresponding to the target application program is obtained; obtaining reconnection parameters of the package in the package object; the reconnection parameters include: enabling attribute of disconnection reconnection function and disconnection reconnection interval time; and if the disconnection reconnection function enabling attribute is determined to be the disconnection reconnection function, performing reconnection operation on the target application program according to the disconnection reconnection interval time and the thread type of the target application program for disconnecting the long connection so as to avoid the situations of main thread congestion, ANR abnormity and performance waste.
Example two
Fig. 2 is a flowchart of a network long connection method in a second embodiment of the present invention, which is optimized based on the above embodiments, in this embodiment, performing a reconnection operation on the target application according to the interval time of the disconnection reconnection and the thread type of the target application for disconnecting the long connection includes: if the thread type of the target application program disconnected with the long connection is determined to be the main thread of the target application program, immediately executing reconnection operation on the target application program; and if the thread type of the target application program disconnected with the long connection is determined to be the non-main thread of the application program, the reconnection operation on the target application program is executed according to the interval time of disconnection reconnection.
As shown in fig. 2, the method of this embodiment specifically includes the following steps:
s210, when the target application program is detected to meet the long connection reconnection condition, acquiring a packaging object corresponding to the target application program.
S220, obtaining reconnection parameters of the package in the package object; the reconnection parameters include: the disconnection reconnect function enables attributes and the interval time of disconnection reconnect.
And S230, if the disconnection reconnection function enabling attribute is determined to be the disconnection reconnection function, and if the thread type of the target application program disconnected with the long connection is determined to be the main thread of the target application program, immediately executing reconnection operation on the target application program.
The thread type of the target application program with the disconnected long connection can be a main thread of the target application program, can also be a non-main thread of the target application program, and can also comprise the main thread of the target application program and the non-main thread of the target application program.
Specifically, if the disconnection reconnection function enabling attribute is determined to be the disconnection reconnection function, if the thread type of the target application program for disconnecting the long connection is the main thread of the target application program, the reconnection operation on the target application program is immediately executed. Since the disconnection of the main thread may cause disconnection of other threads related to the main thread, if the main thread is the main thread, the reconnection operation needs to be performed immediately.
S240, if the enabling attribute of the disconnection reconnection function is determined to be the disconnection reconnection function, if the thread type of the target application program disconnected with the long connection is determined to be the non-main thread of the application program, the reconnection operation on the target application program is executed according to the interval time of disconnection reconnection.
Specifically, if the disconnection reconnection function enabling attribute is determined to be the disconnection reconnection function, and if the thread type of the target application program for disconnecting the long connection is determined to be the non-main thread of the application program, the reconnection operation on the target application program is executed according to the disconnection reconnection interval time in the reconnection parameters, for example, if the disconnection reconnection interval time in the reconnection parameters is 3 seconds, the reconnection operation is executed after the disconnection reconnection function enabling attribute is determined to be the disconnection reconnection function, and the thread type of the target application program for disconnecting the long connection is determined to be the non-main thread of the application program, and the reconnection operation is executed after the interval of 3 seconds.
Optionally, the reconnection parameters further include: the number of reconnection after disconnection.
The number of reconnection times may be set by a user or a system, which is not limited in the embodiment of the present invention.
If the disconnection reconnection function enabling attribute is determined to be the disconnection reconnection function, performing reconnection operation on the target application program according to the disconnection reconnection interval time and the thread type of the target application program for disconnecting the long connection, specifically comprising:
and if the disconnection reconnection function enabling attribute is determined to be the disconnection reconnection function, and the total currently recorded disconnection reconnection times do not exceed the disconnection reconnection times in the reconnection parameters, executing reconnection operation on the target application program according to the disconnection reconnection interval time and the thread type of the target application program for disconnecting the long connection.
Specifically, if it is determined that the disconnection reconnection function enabling attribute is that the disconnection reconnection function is started, it is determined whether the currently recorded total number of disconnection reconnection times exceeds the number of disconnection reconnection times in the reconnection parameter, and if the currently recorded total number of disconnection reconnection times does not exceed the number of disconnection reconnection times in the reconnection parameter, reconnection operation on the target application program is executed according to the interval time of disconnection reconnection and the thread type of disconnection of the target application program. And if the total number of the currently recorded disconnection reconnection times exceeds the disconnection reconnection times in the reconnection parameters, not performing subsequent operation. For example, if the total number of disconnection reconnection times is 10 times and the total number of currently recorded disconnection reconnection times is 8 times, the reconnection operation for the target application program is executed, and if the total number of disconnection reconnection times is 10 times and the total number of currently recorded disconnection reconnection times is 11 times, the reconnection operation for the target application program is not executed.
After the reconnection operation on the target application program is executed according to the interval time of disconnection reconnection and the thread type of disconnection of the target application program, the method further comprises the following steps:
and updating the total disconnection reconnection times of the current record.
Specifically, after the reconnection operation is performed, one is added to the total number of disconnection reconnection times currently recorded, for example, if the total number of disconnection reconnection times is 10 times and the total number of disconnection reconnection times currently recorded is 8 times, the reconnection operation on the target application program is performed, and after the reconnection operation, the total number of disconnection reconnection times currently recorded is updated to 9 times by adding one to the total coefficient of disconnection reconnection times currently recorded.
By setting the number of disconnection reconnection times, performance waste can be avoided. In a specific example, the reconnection parameters are stored in an object according to default values, the object is transferred to a long-connection class when in use, and the long-connection class takes the parameters and then sets the parameters in a corresponding method.
Optionally, when it is detected that the target application satisfies the long connection reconnection condition, before obtaining the encapsulation object corresponding to the target application, the method further includes:
establishing websocket long connection communication through the okhttp;
using a subscriber of rxjava to monitor a callback function;
and if the callback function is a preset function, determining that the target application program meets the long connection reconnection condition.
Optionally, the preset function is an oneerror method.
Optionally, before obtaining the reconnection parameters encapsulated in the encapsulated object, the method further includes:
and obtaining the encapsulated object by using the rxjava encapsulation reconnection parameter.
The websocket long connection is established through okhttp, a subscriber of rxjava is used for subscribing a callback function related to the long connection, if the long connection callback function calls an oneerror method, the reconnection function of rxjava is notified to carry out reconnection operation, and if the oneMessageReiceve method is called, a message is distributed to a message processing center through the rxjava to carry out message processing.
According to the technical scheme of the embodiment, when a target application program is detected to meet a long connection reconnection condition, a packaging object corresponding to the target application program is obtained, and reconnection parameters packaged in the packaging object are obtained; the reconnection parameters include: the disconnection reconnect function enables attributes and the interval time of disconnection reconnect. And if the enabling attribute of the disconnection reconnection function is determined to be the disconnection reconnection function, if the thread type of the target application program disconnected with the long connection is determined to be the main thread of the target application program, immediately executing reconnection operation on the target application program. If the disconnection reconnection function enabling attribute is determined to be the disconnection reconnection function, if the type of the thread for disconnecting the long connection of the target application program is determined to be the non-main thread of the application program, the reconnection operation on the target application program is executed according to the disconnection reconnection interval time, and different interval times are set by distinguishing the main thread from the non-main thread, so that the situations of congestion of the main thread, ANR abnormity and performance waste are avoided.
EXAMPLE III
Fig. 3 is a schematic structural diagram of a network long connection device according to a third embodiment of the present invention. The present embodiment may be applicable to a network long connection situation, where the apparatus may be implemented in a software and/or hardware manner, and the apparatus may be integrated in any device providing a network long connection function, as shown in fig. 3, where the network long connection apparatus specifically includes: a first acquisition module 310, a second acquisition module 320, and an execution module 330.
The first obtaining module 310 is configured to obtain a package object corresponding to a target application program when it is detected that the target application program meets a long connection reconnection condition;
a second obtaining module 320, configured to obtain reconnection parameters of a package in the package object; the reconnection parameters include: enabling attribute of disconnection reconnection function and disconnection reconnection interval time;
the executing module 330 is configured to, if it is determined that the disconnection reconnection function enabling attribute is to start the disconnection reconnection function, execute a reconnection operation on the target application program according to the interval time of the disconnection reconnection and the thread type of the target application program for disconnecting the long connection.
Optionally, the execution module is specifically configured to:
if the thread type of the target application program disconnected with the long connection is determined to be the main thread of the target application program, immediately executing reconnection operation on the target application program;
and if the thread type of the target application program disconnected with the long connection is determined to be the non-main thread of the application program, the reconnection operation on the target application program is executed according to the interval time of disconnection reconnection.
Optionally, the reconnection parameters further include: the number of reconnection times;
the execution module comprises:
a reconnection operation executing unit, configured to, if it is determined that the disconnection reconnection function enabling attribute is to start a disconnection reconnection function and the currently recorded total number of disconnection reconnection times does not exceed the number of disconnection reconnection times in the reconnection parameter, execute a reconnection operation on the target application program according to the interval time of the disconnection reconnection and the thread type of the target application program for disconnecting the long connection;
further comprising:
and the updating unit is used for updating the total times of disconnection reconnection of the current record.
Optionally, the method further includes:
the system comprises an establishing module, a packaging module and a processing module, wherein the establishing module is used for establishing a database of the corresponding relation between an application program and a packaging object in advance;
the first obtaining module is specifically configured to:
and when detecting that the target application program meets the long connection reconnection condition, searching the database to obtain a packaging object which is packaged with reconnection parameters and corresponds to the target application program.
The product can execute the method provided by any embodiment of the invention, and has corresponding functional modules and beneficial effects of the execution method.
According to the technical scheme of the embodiment, when the fact that the target application program meets the long connection reconnection condition is detected, a packaging object corresponding to the target application program is obtained; obtaining reconnection parameters of the package in the package object; the reconnection parameters include: enabling attribute of disconnection reconnection function and disconnection reconnection interval time; and if the disconnection reconnection function enabling attribute is determined to be the disconnection reconnection function, performing reconnection operation on the target application program according to the disconnection reconnection interval time and the thread type of the target application program for disconnecting the long connection so as to avoid the situations of main thread congestion, ANR abnormity and performance waste.
Example four
Fig. 4 is a schematic structural diagram of a computer device in the fourth embodiment of the present invention. FIG. 4 illustrates a block diagram of an exemplary computer device 12 suitable for use in implementing embodiments of the present invention. The computer device 12 shown in FIG. 4 is only one example and should not bring any limitations to the functionality or scope of use of embodiments of the present invention.
As shown in FIG. 4, computer device 12 is in the form of a general purpose computing device. The components of computer device 12 may include, but are not limited to: one or more processors or processing units 16, a system memory 28, and a bus 18 that couples various system components including the system memory 28 and the processing unit 16.
The system memory 28 may include computer system readable media in the form of volatile memory, such as Random Access Memory (RAM)30 and/or cache memory 32. Computer device 12 may further include other removable/non-removable, volatile/nonvolatile computer system storage media. By way of example only, storage system 34 may be used to read from and write to non-removable, nonvolatile magnetic media (not shown in FIG. 4, and commonly referred to as a "hard drive"). Although not shown in FIG. 4, a magnetic disk drive for reading from and writing to a removable, nonvolatile magnetic disk (e.g., a "floppy disk") and an optical disk drive for reading from or writing to a removable, nonvolatile optical disk (e.g., a CD-ROM, DVD-ROM, or other optical media) may be provided. In these cases, each drive may be connected to bus 18 by one or more data media interfaces. Memory 28 may include at least one program product having a set (e.g., at least one) of program modules that are configured to carry out the functions of embodiments of the invention.
A program/utility 40 having a set (at least one) of program modules 42 may be stored, for example, in memory 28, such program modules 42 including, but not limited to, an operating system, one or more application programs, other program modules, and program data, each of which examples or some combination thereof may comprise an implementation of a network environment. Program modules 42 generally carry out the functions and/or methodologies of the described embodiments of the invention.
The processing unit 16 executes various functional applications and data processing by running programs stored in the system memory 28, for example, to implement the network long connection method provided by the embodiment of the present invention: when detecting that a target application program meets a long connection reconnection condition, acquiring a packaging object corresponding to the target application program; obtaining reconnection parameters of the package in the package object; the reconnection parameters include: enabling attribute of disconnection reconnection function and disconnection reconnection interval time; and if the disconnection reconnection function enabling attribute is determined to be the disconnection reconnection function, performing reconnection operation on the target application program according to the disconnection reconnection interval time and the thread type of the target application program for disconnecting the long connection.
EXAMPLE five
An embodiment five of the present invention provides a computer-readable storage medium, on which a computer program is stored, where the computer program, when executed by a processor, implements the network long connection method provided in all the inventive embodiments of the present application: when detecting that a target application program meets a long connection reconnection condition, acquiring a packaging object corresponding to the target application program; obtaining reconnection parameters of the package in the package object; the reconnection parameters include: enabling attribute of disconnection reconnection function and disconnection reconnection interval time; and if the disconnection reconnection function enabling attribute is determined to be the disconnection reconnection function, performing reconnection operation on the target application program according to the disconnection reconnection interval time and the thread type of the target application program for disconnecting the long connection.
Any combination of one or more computer-readable media may be employed. The computer readable medium may be a computer readable signal medium or a computer readable storage medium. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples (a non-exhaustive list) of the computer readable storage medium would include the following: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the context of this document, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device.
A computer readable signal medium may include a propagated data signal with computer readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated data signal may take any of a variety of forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device.
Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.
Computer program code for carrying out operations for aspects of the present invention may be written in any combination of one or more programming languages, including an object oriented programming language such as Java, Smalltalk, C + + or the like and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or the connection may be made to an external computer (for example, through the Internet using an Internet service provider).
It is to be noted that the foregoing is only illustrative of the preferred embodiments of the present invention and the technical principles employed. It will be understood by those skilled in the art that the present invention is not limited to the particular embodiments described herein, but is capable of various obvious changes, rearrangements and substitutions as will now become apparent to those skilled in the art without departing from the scope of the invention. Therefore, although the present invention has been described in greater detail by the above embodiments, the present invention is not limited to the above embodiments, and may include other equivalent embodiments without departing from the spirit of the present invention, and the scope of the present invention is determined by the scope of the appended claims.
Claims (10)
1. A method for long connection in a network, comprising:
when detecting that a target application program meets a long connection reconnection condition, acquiring a packaging object corresponding to the target application program;
obtaining reconnection parameters of the package in the package object; the reconnection parameters include: enabling attribute of disconnection reconnection function and disconnection reconnection interval time;
and if the disconnection reconnection function enabling attribute is determined to be the disconnection reconnection function, performing reconnection operation on the target application program according to the disconnection reconnection interval time and the thread type of the target application program for disconnecting the long connection.
2. The method of claim 1, wherein performing the reconnect operation to the target application according to the interval time of the disconnection reconnect and the thread type of the disconnection long connection of the target application comprises:
if the thread type of the target application program disconnected with the long connection is determined to be the main thread of the target application program, immediately executing reconnection operation on the target application program;
and if the thread type of the target application program disconnected with the long connection is determined to be the non-main thread of the application program, the reconnection operation on the target application program is executed according to the interval time of disconnection reconnection.
3. The method according to claim 1 or 2, wherein the reconnect parameter further comprises: the number of reconnection times;
if the disconnection reconnection function enabling attribute is determined to be the disconnection reconnection function, performing reconnection operation on the target application program according to the disconnection reconnection interval time and the thread type of the target application program for disconnecting the long connection, specifically comprising:
if the disconnection reconnection function enabling attribute is determined to be the disconnection reconnection function, and the currently recorded total disconnection reconnection times do not exceed the disconnection reconnection times in the reconnection parameters, then according to the disconnection reconnection interval time and the thread type of the target application program for disconnecting long connection, the reconnection operation on the target application program is executed;
after the reconnection operation on the target application program is executed according to the interval time of disconnection reconnection and the thread type of disconnection of the target application program, the method further comprises the following steps:
and updating the total disconnection reconnection times of the current record.
4. The method according to claim 1, wherein before acquiring the encapsulation object corresponding to the target application when detecting that the target application satisfies the long connection reconnection condition, the method further comprises:
a database about the corresponding relation between the application program and the packaging object is established in advance;
when detecting that the target application program meets the long connection reconnection condition, acquiring reconnection parameters packaged in the packaged object, wherein the reconnection parameters comprise:
and when detecting that the target application program meets the long connection reconnection condition, searching the database to obtain a packaging object which is packaged with reconnection parameters and corresponds to the target application program.
5. The method according to claim 1, wherein before acquiring the encapsulation object corresponding to the target application when detecting that the target application satisfies the long connection reconnection condition, the method further comprises:
establishing websocket long connection communication through the okhttp;
using a subscriber of rxjava to monitor a callback function;
and if the callback function is a preset function, determining that the target application program meets the long connection reconnection condition.
6. The method of claim 5, wherein the predetermined function is an oneror method.
7. The method of claim 5, wherein before obtaining the reconnect parameters of the package in the package object, further comprising:
and obtaining the encapsulated object by using the rxjava encapsulation reconnection parameter.
8. A network long connection device, comprising:
the device comprises a first acquisition module, a second acquisition module and a third acquisition module, wherein the first acquisition module is used for acquiring a packaging object corresponding to a target application program when the target application program is detected to meet a long connection reconnection condition;
a second obtaining module, configured to obtain reconnection parameters encapsulated in the encapsulated object; the reconnection parameters include: enabling attribute of disconnection reconnection function and disconnection reconnection interval time;
and the execution module is used for executing reconnection operation on the target application program according to the interval time of disconnection reconnection and the thread type of disconnection of the target application program.
9. A computer device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, characterized in that the processor implements the method according to any of claims 1-7 when executing the program.
10. A computer-readable storage medium, on which a computer program is stored which, when being executed by a processor, carries out the method according to any one of claims 1-7.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201811039057.7A CN110881224B (en) | 2018-09-06 | 2018-09-06 | Network long connection method, device, equipment and storage medium |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201811039057.7A CN110881224B (en) | 2018-09-06 | 2018-09-06 | Network long connection method, device, equipment and storage medium |
Publications (2)
Publication Number | Publication Date |
---|---|
CN110881224A true CN110881224A (en) | 2020-03-13 |
CN110881224B CN110881224B (en) | 2021-11-09 |
Family
ID=69727148
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201811039057.7A Active CN110881224B (en) | 2018-09-06 | 2018-09-06 | Network long connection method, device, equipment and storage medium |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN110881224B (en) |
Cited By (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN111835861A (en) * | 2020-07-21 | 2020-10-27 | 平安国际智慧城市科技股份有限公司 | Examination system data processing method and device, computer equipment and storage medium |
CN112087772A (en) * | 2020-10-10 | 2020-12-15 | Oppo(重庆)智能科技有限公司 | Network abnormity recovery method, terminal and computer storage medium |
CN116055227A (en) * | 2023-03-31 | 2023-05-02 | 北京国信会视科技有限公司 | Intelligent terminal management and control method, system and device based on android device online security |
Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN102271123A (en) * | 2010-06-01 | 2011-12-07 | 阿里巴巴集团控股有限公司 | Communication method, system and equipment |
CN102821152A (en) * | 2012-08-08 | 2012-12-12 | 许继集团有限公司 | Information interaction method for family intelligent interaction terminal |
US8732810B2 (en) * | 2011-10-27 | 2014-05-20 | Cellco Partnership | IP push platform and connection protocol in a push notification framework |
CN108430116A (en) * | 2018-03-02 | 2018-08-21 | 杭州朗和科技有限公司 | Suspension reconnection method, medium, device and computing device |
-
2018
- 2018-09-06 CN CN201811039057.7A patent/CN110881224B/en active Active
Patent Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN102271123A (en) * | 2010-06-01 | 2011-12-07 | 阿里巴巴集团控股有限公司 | Communication method, system and equipment |
US8732810B2 (en) * | 2011-10-27 | 2014-05-20 | Cellco Partnership | IP push platform and connection protocol in a push notification framework |
CN102821152A (en) * | 2012-08-08 | 2012-12-12 | 许继集团有限公司 | Information interaction method for family intelligent interaction terminal |
CN108430116A (en) * | 2018-03-02 | 2018-08-21 | 杭州朗和科技有限公司 | Suspension reconnection method, medium, device and computing device |
Cited By (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN111835861A (en) * | 2020-07-21 | 2020-10-27 | 平安国际智慧城市科技股份有限公司 | Examination system data processing method and device, computer equipment and storage medium |
CN112087772A (en) * | 2020-10-10 | 2020-12-15 | Oppo(重庆)智能科技有限公司 | Network abnormity recovery method, terminal and computer storage medium |
CN112087772B (en) * | 2020-10-10 | 2023-04-07 | Oppo(重庆)智能科技有限公司 | Network anomaly recovery method, terminal and computer storage medium |
CN116055227A (en) * | 2023-03-31 | 2023-05-02 | 北京国信会视科技有限公司 | Intelligent terminal management and control method, system and device based on android device online security |
CN116055227B (en) * | 2023-03-31 | 2023-06-16 | 北京国信会视科技有限公司 | Intelligent terminal management and control method, system and device based on android device online security |
Also Published As
Publication number | Publication date |
---|---|
CN110881224B (en) | 2021-11-09 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN110881224B (en) | Network long connection method, device, equipment and storage medium | |
CN113900834B (en) | Data processing method, device, equipment and storage medium based on Internet of things technology | |
US11269705B2 (en) | Method and apparatus for outputting information | |
CN110377341B (en) | Method, device, medium and electronic equipment for monitoring no-response exception | |
CN109783345B (en) | Method and system for testing small program performance | |
US20150193280A1 (en) | Method and device for monitoring api function scheduling in mobile terminal | |
CN107644075B (en) | Method and device for collecting page information | |
CN108052407A (en) | A kind of application crash means of defence, device, equipment and storage medium | |
CN112965799B (en) | Task state prompting method and device, electronic equipment and medium | |
CN110275701B (en) | Data processing method, device, medium and computing equipment | |
CN110893616B (en) | Remote control method and device, computer equipment and storage medium | |
CN111290873B (en) | Fault processing method and device | |
CN110764995B (en) | Method, device, medium and electronic equipment for detecting file access abnormality | |
CN109756393B (en) | Information processing method, system, medium, and computing device | |
CN113760631A (en) | Page loading duration determination method, device, equipment and storage medium | |
CN113760693A (en) | Method and apparatus for local debugging of microservice systems | |
CN114826886B (en) | Disaster recovery method and device for application software and electronic equipment | |
CN110912720B (en) | Information generation method and device | |
US11941432B2 (en) | Processing system, processing method, higher-level system, lower-level system, higher-level program, and lower-level program | |
CN107480004B (en) | Fault recovery method and device and computer equipment | |
CN115686911A (en) | Server-side self-checking method and device, electronic equipment and storage medium | |
CN111475322A (en) | Method and device for positioning stuck thread, computer equipment and readable storage medium | |
US20130300557A1 (en) | Alert and response messaging between devices | |
CN114064314A (en) | Service message processing method, system, electronic device and computer readable medium | |
CN114491674A (en) | Log processing method, device and equipment based on block chain |
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 |