Disclosure of Invention
The invention aims to provide a method and a device for switching a dual-card data network, a storage medium and terminal equipment, and solves the problems of network delay and poor user experience caused by manual switching of the data network at present.
The invention provides a double-card data network switching method, which comprises the following steps:
acquiring a network data packet of a first SIM card used currently, and extracting a plurality of high-frequency IP addresses corresponding to an application program from the network data packet;
sequentially polling and judging whether each high-frequency IP address has network delay according to a first preset period, and accumulating the times of the high-frequency IP addresses judged to have the network delay;
judging whether the accumulated network delay times are greater than preset times or not;
if the accumulated network delay times are larger than the preset times, simultaneously measuring the delay time of all the high-frequency IP addresses, and calculating the average delay time according to the delay time of all the high-frequency IP addresses;
judging whether the average delay time is greater than a first preset time or not;
and if the average delay time is greater than a first preset time, switching to a second SIM card for connecting a data network.
The double-card data network switching method provided by the invention has the following beneficial effects: the network delay of each high-frequency IP address is monitored in real time by sequentially polling in a first preset period, a plurality of high-frequency IP addresses are singly detected according to a certain time period, the resource consumption is low, and the delay time of all the high-frequency IP addresses can be triggered and completely evaluated only when the accumulated network delay times are greater than the preset times, so that the resource waste can be avoided; and automatically switching the SIM card according to the average delay time, and realizing automatic switching to use a data network, thereby improving the user experience.
In addition, the dual-card data network switching method provided by the invention can also have the following additional technical characteristics:
further, extracting a target IP address from the network data packet, and judging whether the target IP address is in a first IP address queue;
if the target IP address is not in the first IP address queue, adding the target IP address to the first IP address queue;
if the target IP address is in the first IP address queue, removing the target IP address from the first IP address queue, and judging whether the target IP address is in a second IP address queue;
and if the target IP address is not in the second IP address queue, adding the target IP address into the second IP address queue, and determining the target IP address as a newly-added high-frequency IP address.
Further, the first IP address queue is a fixed length queue.
Further, the second IP address queue is a fixed length queue.
Further, the high-frequency IP address is a destination IP address that appears at least twice in the network packet.
Further, the step of calculating the average delay time according to the delay times of all the high-frequency IP addresses specifically includes:
and removing the delay time of the high-frequency IP address positioned at the highest delay time and the delay time of the high-frequency IP address positioned at the lowest delay time, and averaging the delay times of the rest high-frequency IP addresses.
Further, the step of sequentially polling and monitoring the network delay of each high-frequency IP address in the first preset period specifically includes:
if the network delay of the high-frequency IP address is monitored for the first time, the first preset period is subjected to period shortening processing to obtain a second preset period, and whether the network delay exists in the remaining high-frequency IP addresses or not is judged according to the second preset period through polling in sequence.
The invention also provides a double-card data network switching device, which comprises:
the address extraction module is used for acquiring a network data packet of a first SIM card used currently and extracting a plurality of high-frequency IP addresses from the network data packet;
the frequency accumulation module is used for sequentially polling and judging whether network delay exists in each high-frequency IP address according to a first preset period and accumulating the frequency of the high-frequency IP address judged as the network delay;
the first judgment module is used for judging whether the accumulated network delay times are greater than preset times or not;
the first processing module is used for measuring the delay time of all the high-frequency IP addresses simultaneously when the accumulated network delay times are larger than the preset times, and calculating the average delay time according to the delay time of all the high-frequency IP addresses;
the second judgment module is used for judging whether the average delay time is greater than a first preset time or not;
and the second processing module is used for switching to the second SIM card for connecting the data network when the average delay time is greater than the first preset time.
The present invention also provides a computer-readable storage medium having stored thereon a computer program which, when executed by a processor, implements the above-described dual-card data network switching method.
The invention also provides a terminal device, which comprises a memory, a processor and a computer program which is stored on the memory and can run on the processor, wherein the processor executes the program to realize the double-card data network switching method.
Additional aspects and advantages of the invention will be set forth in part in the description which follows and, in part, will be obvious from the description, or may be learned by practice of the invention.
Detailed Description
In order to make the objects, features and advantages of the present invention comprehensible, embodiments accompanied with figures are described in detail below. Several embodiments of the invention are presented in the drawings. This invention may, however, be embodied in many different forms and should not be construed as limited to the embodiments set forth herein. Rather, these embodiments are provided so that this disclosure will be thorough and complete.
The embodiment of the invention provides a double-card data network switching method which can be applied to a mobile phone terminal, wherein the mobile phone terminal comprises a first SIM card and a second SIM card which belong to different operators, the mobile phone terminal is loaded with an application program, and when a user uses the application program, the application program is interacted with a server through a data network connected with the first SIM card or the second SIM card.
Fig. 1 is a flowchart of a dual-card data network switching method according to a first embodiment of the present invention, which includes the following steps:
step S101, obtaining a network data packet of a first SIM card used currently, and extracting a plurality of high-frequency IP addresses corresponding to an application program from the network data packet;
the mobile phone terminal uses a first SIM card at present, an application program interacts with a server through a data network connected with the first SIM card, the application program is Baidu APP, a microblog APP, a WeChat APP and the like, a high-frequency IP address is an IP address corresponding to the application program frequently used by a user recently, a plurality of high-frequency IP addresses are sent to the server through a data network connected with the first SIM card to form a network data packet of the first SIM card, the mobile terminal obtains the network data packet of the first SIM card sent by the server and extracts a plurality of high-frequency IP addresses from the network data packet, and in the first embodiment, 8 high-frequency IP addresses are stored in the network data packet of the first SIM card.
Step S102, sequentially polling and judging whether each high-frequency IP address has network delay according to a first preset period, and accumulating the times of the high-frequency IP addresses judged to have the network delay;
step S103, judging whether the accumulated network delay times are greater than preset times;
in a first embodiment of the present invention, a first preset period is set to about 2S, that is, each high-frequency IP address is sequentially monitored every 2S, each detection consumes less resources, and whether a network delay exists is monitored, for example, when the network delay time of the high-frequency IP address is greater than 600ms, which is recorded as 1 network delay, the number of network delays in a certain time is counted, for example, when 3 network delays are accumulated within 3600ms, the starting step S103 is triggered.
Step S104, if the accumulated network delay times are larger than the preset times, simultaneously measuring all the delay time of the high-frequency IP addresses, and calculating the average delay time according to all the delay time of the high-frequency IP addresses;
in specific implementation, when the accumulated network delay times are greater than the preset times, high-strength network quality evaluation is started, that is, 8 high-frequency IP addresses are detected simultaneously, 10 detections are performed on each high-frequency IP address, and finally, 80 delay time data are calculated to calculate the average delay time.
Step S105, judging whether the average delay time is greater than a first preset time;
the first preset time may be 600ms, if the average delay time is greater than 600ms, the operation of switching to the second SIM card in step S105 is performed, and if the average delay time is not greater than 600ms, the operation of switching the data card is not performed, and step S102 is performed.
And step S106, if the average delay time is greater than a first preset time, switching to a second SIM card to connect a data network.
Only when the accumulated network delay times are greater than the preset times, the delay time for completely evaluating all the high-frequency IP addresses is triggered, so that the waste of resources can be avoided; and automatically switching the SIM card according to the average delay time, and realizing automatic switching to use a data network, thereby improving the user experience.
Fig. 2 is a method for acquiring a high-frequency IP address in a first embodiment of the present invention, which specifically includes the following sub-steps:
step 1011, extracting a target IP address from the network data packet, and judging whether the target IP address is in a first IP address queue;
step 1012, if the target IP address is not in the first IP address queue, adding the target IP address to the first IP address queue;
step 1013, if the target IP address is in the first IP address queue, removing the target IP address from the first IP address queue, and determining whether the target IP address is in a second IP address queue;
step 1014, if the target IP address is not in the second IP address queue, adding the target IP address into the second IP address queue, and determining the target IP address as a newly added high-frequency IP address.
In specific implementation, the IP addresses of the application program used by the user in the near term are stored in the first IP address queue, where the first IP address queue is preferably a fixed-length queue, that is, only a fixed number of IP addresses can be arranged in the first IP address queue according to the time sequence, for example, when the fixed length is 8, a maximum of 8 target IP addresses are arranged in the first IP address queue. In step 1013, after the IP address is removed from the first IP address queue, the queue position occupied by the target IP address in the first IP address queue will be marked as a vacancy, and a subsequent IP address (the target IP address obtained instep 1011 again) may be added to the vacancy in the first IP address queue, when there is no vacancy in the first IP address queue, the target IP address may be added to the tail of the first IP address queue, and when the first IP address queue is a fixed-length queue, after the target IP address is added to the tail of the first IP address queue, the queue length of the first IP address queue will exceed the fixed length, and at this time, the target IP address at the head of the first IP address queue may be removed, that is, the target IP address of the first IP address queue is dynamically changed.
In specific implementation, the second IP address queue is preferably a queue with a fixed length, for example, the fixed length is 8, a target IP address can only appear in the first IP address queue at least twice and can enter the second IP address queue, at this time, the IP address is a newly added high-frequency IP address, which is also called a high-frequency IP address, and the high-frequency IP address is an application program frequently visited by a user, so that network quality monitoring and network quality evaluation are performed on the high-frequency IP address, and the experience of the user can be improved.
In specific implementation, the method for calculating the average delay time in the first embodiment of the present invention specifically includes:
step S1041, removing the delay time of the high frequency IP address located at the highest delay time and the delay time of the high frequency IP address located at the lowest delay time, and averaging the delay times of the remaining high frequency IP addresses.
Specifically, for example, a total of 8 high-frequency IP addresses are provided, each high-frequency IP address is subjected to 10 delay time measurements, there are totally 80 delay time data, the delay times of all the high-frequency IP addresses are sorted from small to large, one highest delay time and one lowest delay time are removed, and the remaining 78 delay times are averaged, so that the accuracy of the average delay time is ensured.
In specific implementation, the step of sequentially polling and monitoring the network delay of each high-frequency IP address in the first preset period in the first embodiment of the present invention specifically includes:
step S1021, if the network delay of the high-frequency IP address is monitored for the first time, cycle shortening is carried out on the first preset cycle to obtain a second preset cycle, and whether the network delay exists in the remaining high-frequency IP addresses or not is judged by polling in sequence according to the second preset cycle.
Specifically, for example, the first preset period is 2s, when the network delay of the high-frequency IP address is monitored for the first time, the first preset period is shortened, for example, the second preset period is set to 1s, and whether the network delay exists in each remaining high-frequency IP address is sequentially polled according to the second preset period. And then accelerate the monitoring efficiency of the network quality, thus raise the efficiency of switching over the data card.
Fig. 3 is a block diagram of a dual-card data network switching apparatus according to a second embodiment of the present invention, the apparatus includes:
theaddress extraction module 10 is configured to acquire a network data packet of a currently used first SIM card, and extract a plurality of high-frequency IP addresses corresponding to an application program from the network data packet;
thenumber accumulation module 20 is configured to sequentially poll and judge whether each high-frequency IP address has a network delay according to a first preset period, and perform number accumulation on the high-frequency IP addresses judged to have the network delay;
a first determiningmodule 30, configured to determine whether the accumulated network delay times are greater than a preset time;
afirst processing module 40, configured to measure delay times of all the high-frequency IP addresses simultaneously when the accumulated network delay times are greater than the preset times, and calculate an average delay time according to the delay times of all the high-frequency IP addresses;
a second determiningmodule 50, configured to determine whether the average delay time is greater than a first preset time;
thesecond processing module 60 is configured to switch to the second SIM card connection data network when the average delay time is greater than a first preset time.
Referring to fig. 4, specifically, the address extracting module includes:
a third determiningmodule 11, configured to extract a target IP address from the network data packet, and determine whether the target IP address is in the first IP address queue;
athird processing module 12, configured to add the target IP address to the first IP address queue if the target IP address is not in the first IP address queue;
a fourth determiningmodule 13, configured to remove the target IP address from the first IP address queue when the target IP address is in the first IP address queue, and determine whether the target IP address is in a second IP address queue;
and afourth processing module 14, configured to add the target IP address to the second IP address queue if the target IP address is not in the second IP address queue, and determine the target IP address as a newly added high-frequency IP address.
Specifically, the apparatus further comprises:
and the delay calculation module is used for removing the delay time of the high-frequency IP address positioned at the highest delay time and the delay time of the high-frequency IP address positioned at the lowest delay time, and averaging the delay times of the rest high-frequency IP addresses.
Specifically, the apparatus further comprises:
and the period processing module is used for shortening the period of the first preset period to obtain a second preset period when the network delay of the high-frequency IP address is monitored for the first time, and polling and judging whether the network delay exists in the rest high-frequency IP addresses according to the second preset period.
In summary, the dual-card data network switching method provided by the present invention has the following beneficial effects: the network delay of each high-frequency IP address is monitored in real time by sequentially polling in a first preset period, the single detection resource consumption of a plurality of high-frequency IP addresses is low according to a certain time period, and the delay time of all the high-frequency IP addresses can be triggered and completely evaluated only when the accumulated network delay times are greater than the preset times, so that the waste of resources can be avoided; and automatically switching the SIM card according to the average delay time, and realizing automatic switching to use a data network, thereby improving the user experience.
Embodiments of the present invention also provide a computer-readable storage medium, on which a computer program is stored, which when executed by a processor implements the dual-card data network switching method as described above.
Embodiments of the present invention also provide a terminal device, which includes a memory, a processor, and a computer program stored in the memory and executable on the processor, and when the processor executes the program, the dual-card data network switching method is implemented.
The above-mentioned embodiments only express several embodiments of the present invention, and the description thereof is more specific and detailed, but not construed as limiting the scope of the present invention. It should be noted that, for a person skilled in the art, several variations and modifications can be made without departing from the inventive concept, which falls within the scope of the present invention. Therefore, the protection scope of the present patent shall be subject to the appended claims.