CN110768740A - Time synchronization method and device - Google Patents
Time synchronization method and device Download PDFInfo
- Publication number
- CN110768740A CN110768740A CN201911035308.9A CN201911035308A CN110768740A CN 110768740 A CN110768740 A CN 110768740A CN 201911035308 A CN201911035308 A CN 201911035308A CN 110768740 A CN110768740 A CN 110768740A
- Authority
- CN
- China
- Prior art keywords
- client
- time
- server
- determining
- local
- 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
- H04J—MULTIPLEX COMMUNICATION
- H04J3/00—Time-division multiplex systems
- H04J3/02—Details
- H04J3/06—Synchronising arrangements
- H04J3/0635—Clock or time synchronisation in a network
- H04J3/0638—Clock or time synchronisation among nodes; Internode synchronisation
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04J—MULTIPLEX COMMUNICATION
- H04J3/00—Time-division multiplex systems
- H04J3/02—Details
- H04J3/06—Synchronising arrangements
- H04J3/0635—Clock or time synchronisation in a network
- H04J3/0638—Clock or time synchronisation among nodes; Internode synchronisation
- H04J3/0652—Synchronisation among time division multiple access [TDMA] nodes, e.g. time triggered protocol [TTP]
- H04J3/0655—Synchronisation among time division multiple access [TDMA] nodes, e.g. time triggered protocol [TTP] using timestamps
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04J—MULTIPLEX COMMUNICATION
- H04J3/00—Time-division multiplex systems
- H04J3/02—Details
- H04J3/06—Synchronising arrangements
- H04J3/0635—Clock or time synchronisation in a network
- H04J3/0682—Clock or time synchronisation in a network by delay compensation, e.g. by compensation of propagation delay or variations thereof, by ranging
Landscapes
- Engineering & Computer Science (AREA)
- Computer Networks & Wireless Communication (AREA)
- Signal Processing (AREA)
- Computer And Data Communications (AREA)
Abstract
The invention provides a time synchronization method and a time synchronization device, which are applied to a client and comprise the following steps: when the client receives the operation instruction, a pre-stored time stamp is obtained, wherein the time stamp is the server time in a data packet which is sent to the client by the server last time; calculating a local time length according to a time calculation method corresponding to the type of an application system currently operated by the client, wherein the local time length is the local time length from the time when the client receives the data packet to the time when the client receives the operation instruction; calculating the local time length and the time stamp according to a first algorithm to obtain the current time of the server; and taking the current time of the server as the current time of the client to finish the time synchronization of the client and the server. By applying the method and the system, the client can obtain the current time of the server through calculation, the obtained current time of the server is used as the current time of the client, and the data request is processed according to the current time, so that the accuracy of processing data is improved, and the experience of using the client is improved.
Description
Technical Field
The present invention relates to the field of communications technologies, and in particular, to a time synchronization method and apparatus.
Background
The intelligent terminals become indispensable application products in life of people, and most of the intelligent terminals can carry various application programs and clients. People can realize remote communication through the communication client, or realize the dream that people can shop without going out, and can use the game application to properly entertain in leisure time, and the life of people is more colorful and convenient due to various applications and clients.
Various applications or clients need to process data when realizing functions, and the client usually processes data based on local time. The client cannot acquire the server time of the server in real time, and the local time is easily influenced by external factors to change, so that the local time of the client and the server time may be inconsistent, data processing is prone to errors when the client processes data with the local time as a reference, and the client is abnormal, so that the experience of a user for using the client is reduced.
Disclosure of Invention
In view of this, the present invention provides a time synchronization method, which is used for determining the current time of a server as the current time of a client after the client calculates the current time of the server, and the client processes various data requests according to the determined current time, so as to improve the accuracy of data processing results and improve the experience of a user using the client. The invention also provides a time synchronization device which is used for supporting the application of the time synchronization method provided by the invention in practice.
In order to achieve the purpose, the invention provides the following technical scheme:
a time synchronization method is applied to a client and comprises the following steps:
when the client receives an operation instruction sent by a user, a pre-stored time stamp is obtained, wherein the time stamp is the server time in a data packet sent to the client by a server last time;
determining the type of an application system currently operated by the client, and calculating a local time length according to a time calculation method corresponding to the type of the application system, wherein the local time length is the local time length from the time when the client receives the data packet to the time when the client receives the operation instruction;
calculating the local time length and the timestamp according to a preset first algorithm to obtain the current time of the server;
and taking the current time of the server as the current time of the client, and completing the time synchronization of the client and the server.
Optionally, in the method, the determining a type of an application system currently running by the client, and calculating a local time length according to a time calculation method corresponding to the type of the application system includes:
acquiring a system identifier of an application system currently operated by the client, and determining a system type to which the application system belongs according to the system identifier;
when the application system is a first type system, determining the timing duration in a preset timer when the operation instruction is received, and executing a zero setting operation and starting timing when a client receives a data packet sent by the server by the timer;
and determining the timing duration determined in the timer as the local time length.
Optionally, in the method, the determining a type of an application system currently running by the client, and calculating a local time length according to a time calculation method corresponding to the type of the application system includes:
acquiring a system identifier of an application system currently operated by the client, and determining a system type to which the application system belongs according to the system identifier;
when the application system is a second type system, determining a first operation time length, wherein the first operation time length is a local time length from the start of the client to the reception of the data packet;
determining a second operation duration, wherein the second operation duration is a local duration from the starting to the receiving of the sending instruction by the client;
substituting the second operation duration and the first operation duration into a preset calculation formula for calculation to obtain an operation time difference output by the calculation formula, and determining the operation time difference as the local time length.
The above method, optionally, further includes:
determining the average network delay time of the client;
calculating the timestamp, the local time length and the network delay average time according to a preset second algorithm to obtain the current time of the server;
and taking the current time of the server as the current time of the client, and completing the time synchronization of the client and the server.
The above method, optionally, further includes:
acquiring data to be sent which needs to be sent to a server, wherein the data to be sent is data sent by a user;
determining the current time of the client and determining the preset forbidden time in the client;
and judging whether the current time of the client is greater than the forbidden time, and if the current time of the client is greater than the forbidden time, sending the data to be sent to a server.
A time synchronization device applied to a client comprises:
the first acquisition unit is used for acquiring a pre-stored timestamp when the client receives an operation instruction sent by a user, wherein the timestamp is the server time in a data packet which is sent to the client by a server last time;
a first determining unit, configured to determine a type of an application system currently running by the client, and calculate a local time length according to a time calculation method corresponding to the type of the application system, where the local time length is a local time length from when the client receives the data packet to when the client receives the operation instruction;
the first calculating unit is used for calculating the local time length and the timestamp according to a preset first algorithm to obtain the current time of the server;
and the first synchronization unit is used for taking the current time of the server as the current time of the client and completing the time synchronization of the client and the server.
The above apparatus, optionally, the first determining unit includes:
the first obtaining subunit is configured to obtain a system identifier of an application system currently running on the client, and determine a system type to which the application system belongs according to the system identifier;
the first determining subunit is configured to determine, when the application system is a first type system, a timing duration in a timer preset when the operation instruction is received, where the timer executes a zeroing operation and starts timing when the client receives a data packet sent by the server;
and the second determining subunit is configured to determine the timing duration determined in the timer as the local time length.
The above apparatus, optionally, the first determining unit includes:
the second obtaining subunit is configured to obtain a system identifier of the application system currently running on the client, and determine a system type to which the application system belongs according to the system identifier;
a third determining subunit, configured to determine, when the application system is a second type system, a first running duration, where the first running duration is a local duration from starting to receiving the data packet by the client;
a fourth determining subunit, configured to determine a second operation duration, where the second operation duration is a local duration from the start to the reception of the sending instruction by the client;
and the calculating subunit is used for substituting the second operation time length and the first operation time length into a preset calculation formula to calculate, so as to obtain an operation time difference output by the calculation formula, and determining the operation time difference as the local time length.
The above apparatus, optionally, further comprises:
a second determining unit, configured to determine a network delay average duration of the client;
the second calculation unit is used for calculating the timestamp, the local time length and the network delay average time length according to a preset second algorithm to obtain the current time of the server;
and the second synchronization unit is used for taking the current time of the server as the current time of the client and completing the time synchronization between the client and the server.
The above apparatus, optionally, further comprises:
the second acquiring unit is used for acquiring data to be sent which needs to be sent to the server, wherein the data to be sent is data sent by a user;
a third determining unit, configured to determine a current time of the client and determine a disable-release time preset in the client;
and the judging unit is used for judging whether the current time of the client is greater than the forbidden time, and if the current time of the client is greater than the forbidden time, sending the data to be sent to a server.
Compared with the prior art, the invention has the following advantages:
in the method provided by the invention, when the client receives an operation instruction sent by a user, a pre-stored timestamp is obtained, wherein the timestamp is the server time in a data packet sent to the client by a server last time; determining the type of an application system currently operated by the client, and calculating a local time length according to a time calculation method corresponding to the type of the application system, wherein the local time length is the local time length from the time when the client receives the data packet to the time when the client receives the operation instruction; calculating the local time length and the timestamp according to a preset first algorithm to obtain the current time of the server; and taking the current time of the server as the current time of the client, and completing the time synchronization of the client and the server. By applying the method provided by the invention, the client can actively calculate the current time of the server, and the accuracy of the data processing result is improved by taking the calculated current time of the server as the current time of the client and processing the data according to the current time of the client, so that the use experience of the user application client is improved.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below, it is obvious that the drawings in the following description are only embodiments of the present invention, and for those skilled in the art, other drawings can be obtained according to the provided drawings without creative efforts.
Fig. 1 is a flowchart of a method of time synchronization according to an embodiment of the present invention;
FIG. 2 is a flowchart of another method of a time synchronization method according to an embodiment of the present invention;
FIG. 3 is a flowchart of another method of a time synchronization method according to an embodiment of the present invention;
FIG. 4 is a flowchart of another method of a time synchronization method according to an embodiment of the present invention;
fig. 5 is a device structure diagram of a time synchronization device according to an embodiment of the present invention.
Detailed Description
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 only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
In this application, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other identical elements in a process, method, article, or apparatus that comprises the element.
The invention is operational with numerous general purpose or special purpose computing device environments or configurations. For example: personal computers, server computers, hand-held or portable devices, tablet-type devices, multiprocessor apparatus, distributed computing environments that include any of the above apparatus or devices, and the like.
The embodiment of the present invention provides a time synchronization method, which can be applied to various system platforms, and can be applied to a client terminal operated by a terminal, and an execution subject of the method can be a processor or a server in the terminal, and a method flowchart of the method can refer to fig. 1, and the following description specifically describes:
s101, when the client receives an operation instruction sent by a user, a pre-stored time stamp is obtained, wherein the time stamp is the server time in a data packet sent to the client by a server last time.
In the method provided by the embodiment of the invention, when the client receives an operation instruction sent by a user, the operation instruction indicates that the user sends data to the server or triggers the client to perform data interaction with the server. And acquiring a timestamp pre-stored in a memory, wherein the timestamp is the server time in a data packet which is sent to the client by the server last time. It should be noted that, when receiving a data packet sent by a server, the client analyzes the data packet to obtain a timestamp in the data packet, and stores the timestamp in a preset memory; it should be noted that the timestamp stored in the memory is updated continuously along with the timestamp in the data packet sent by the receiving server. Note that the time stamp is a time point, for example, the time stamp a is 8:45, the time stamp b is 10:01, note that the time stamp may include a date, and may be accurate to seconds or milliseconds.
S102, determining the type of an application system currently operated by the client, and calculating a local time length according to a time calculation method corresponding to the type of the application system, wherein the local time length is the local time length from the time when the client receives the data packet to the time when the client receives the operation instruction.
In the method provided by the embodiment of the invention, the type of an application system currently operated by a client is determined, wherein the type of the application system comprises but is not limited to android, ios, web and other system types; according to the time calculation method corresponding to the type of the application system, the calculation method corresponding to different application systems is different, and the local time length is calculated by using the calculation method, wherein the time unit of the local time length includes but is not limited to minutes, seconds or milliseconds. The local time length is the local time length from the time when the client receives the data packet received last time to the time when the client receives the operation instruction sent by the user.
S103, calculating the local time length and the time stamp according to a preset first algorithm to obtain the current time of the server.
In the method provided by the embodiment of the invention, after the client determines the local time length, calculation is carried out according to a preset first algorithm to obtain the current time of the server. The first algorithm is specifically that the local time length and the time stamp are added, the time point obtained by adding the local time length and the time stamp is the current time of the server, for example, the time stamp is 12 points and 15 minutes, the local time length is 24 minutes, the time stamp and the local time length are calculated according to a preset first algorithm, the obtained time point is 12 points and 39 minutes, and then the current time of the server is 12 points and 39 minutes; it should be noted that, in order to make the calculated time more accurate, the time unit of the time stamp and the local time length includes, but is not limited to, seconds or milliseconds.
And S104, taking the current time of the server as the current time of the client, and completing the time synchronization of the client and the server.
In the method provided by the embodiment of the invention, the current time of the server obtained by calculation is used as the current time of the client, so that the time synchronization between the client and the server is completed. Optionally, the method provided by the present invention can be applied to multiple clients simultaneously, so that the time of the multiple clients is synchronized with the time of the server, and the work efficiency of the whole system is improved.
In the method provided by the embodiment of the invention, when the client receives an operation instruction sent by a user, a pre-stored timestamp is obtained, wherein the timestamp is the server time in a data packet sent to the client by a server last time; determining the type of an application system currently operated by the client, and calculating a local time length according to a time calculation method corresponding to the type of the application system, wherein the local time length is the local time length from the time when the client receives the data packet to the time when the client receives the operation instruction; calculating the local time length and the timestamp according to a preset first algorithm to obtain the current time of the server; and taking the current time of the server as the current time of the client, and completing the time synchronization of the client and the server. By applying the method provided by the invention, the client can actively calculate the current time of the server, the client completes the synchronization with the server time by taking the calculated current time of the server as the current time of the client, and processes the data according to the current time of the client, thereby improving the accuracy of data processing results, reducing the probability of abnormal data processing errors of the client, and improving the use experience of the user application client.
In the method provided in the embodiment of the present invention, when an operation instruction sent by a user is received, a local time length needs to be determined, a manner of determining the local time length is different according to an application system of a client application, and one method flow of determining the local time length is shown in fig. 2, which is described in detail as follows:
s201, obtaining a system identifier of the application system currently operated by the client, and determining the system type of the application system according to the system identifier.
In the method provided by the embodiment of the invention, the system identifiers of the same application system are the same, and the system identifiers of different application systems are different; different system identifiers may belong to different system types, which may include a variety of different application systems. It should be noted that the system identifier may be set according to a programming language of the application system.
S202, when the application system is a first type system, determining the timing duration in a preset timer when the operation instruction is received, and when the client receives a data packet sent by the server, executing a zero setting operation and starting timing by the timer.
In the method provided by the embodiment of the present invention, when the application system is a WEB system, it is determined that the application system belongs to a first type system, where the first type system includes but is not limited to a WEB system; sending a stop instruction to a preset timer, wherein the stop instruction is used for triggering the timer to stop timing; it should be noted that, when the client receives a data packet sent by the server, the timer executes a zero setting operation and starts timing until a stop instruction is received, where the zero setting operation is to zero time data stored in the timer. The condition for the timer to initially count time may be that the client starts counting time while being enabled in the application system, or the timer starts counting time upon receiving a data packet sent by the server.
And S203, determining the timing duration determined in the timer as the local time length.
In the method provided by the embodiment of the invention, when an operation instruction sent by a user is received, the timing duration in a timer when the operation instruction is received is determined, and the timing duration is determined as the local time length; it should be noted that, when the operation instruction is received, the timer does not stop timing; and the timer carries out zero setting operation only when receiving the data packet sent by the server and starts timing from zero.
In the method provided by the embodiment of the present invention, another method for determining the local time length is shown in fig. 3, which is described in detail as follows:
s301, obtaining a system identifier of the application system currently operated by the client, and determining the system type of the application system according to the system identifier.
In the method provided by the embodiment of the present invention, reference may be made to S201 for specific description, and details are not described here.
S302, when the application system is a second type system, determining a first operation duration, wherein the first operation duration is a local duration from the start to the reception of the data packet by the client.
In the method provided by the embodiment of the present invention, when determining that the application system is an android system or an ios system according to the system identifier, it is determined that the application system operated by the client is a second type system, and it should be noted that the second type system includes, but is not limited to, an android system or an ios system. Acquiring the timing duration in a preset timer, wherein the timer starts timing when a client is started, and when a data packet sent by a server is received, determining the timing duration in the timer when the data packet is received, and storing the timing duration in a corresponding memory; it should be noted that the timing duration stored in the memory is the timing duration in the timer when the data packet is received last time, and the timing duration is the first operation duration. It should be noted that another implementation manner of determining the first operation duration may be that a first local timestamp started by the client is determined, a second local timestamp when the data packet is received is determined, the first local timestamp is subtracted from the second local timestamp, the calculated time difference is the first operation duration, the first operation duration is stored in the corresponding memory, the second local timestamp is greater than the first local timestamp, and the received data packet is a data packet received by the client at the last time.
It should be noted that the first operation duration stored in the memory is the duration of the data packet received last time.
S303, determining a second operation time length, wherein the second operation time length is a local time length from the start to the reception of the sending instruction by the client.
In the method provided by the embodiment of the invention, the timing duration in a preset timer is obtained, the timer starts timing when a client starts, when an operation instruction sent by a user is received, the timing duration in the timer when the operation instruction is received is determined, and the timing duration is stored in a corresponding memory; it should be noted that the timing duration is a second operation duration. It should be noted that another implementation manner of determining the second running time length may be that a third local timestamp started by the client is determined, a fourth local timestamp when the operation instruction is received is determined, the fourth local timestamp is subtracted from the third local timestamp, a calculated time difference is the second running time length, and the second running time length is stored in a corresponding memory, where the fourth local timestamp is greater than the third local timestamp; it should be noted that the received operation instruction is received by the client last time.
S304, substituting the second operation duration and the first operation duration into a preset calculation formula for calculation to obtain an operation time difference output by the calculation formula, and determining the operation time difference as the local time length.
In the method provided by the embodiment of the present invention, the preset calculation formula may be: the operating time difference is the second operating time length-the first operating time length; and determining the calculated running time difference as the local time length of the client.
To specifically describe the specific acquisition process of the local time length, a specific example is described as follows:
when the client determines the first running time length by applying the timestamp, assuming that the first timestamp when the client starts to start is 6:00 and the second timestamp when the client receives the data packet z is 6:50, determining that the first running time length is 50 minutes, and storing the first running time length into a corresponding memory; if the timestamp of the client when receiving the data packet x is 6:55, determining that the first operation time is 55 minutes, and updating the first operation time in the memory to be 55 minutes;
when the client determines a first running time length through the application timer, when the client starts, the preset timer starts to time, when the client receives the data packet, the timing time length in the timer is 13 minutes, the first running time length is 13 minutes, and the first running time length is stored; if the client receives the data packet again, the timing duration in the timer is 25 minutes, the first operation duration is 25 minutes, and the first operation duration stored in the corresponding memory is updated;
assuming that the duration of the client from startup to the last time the client received a data packet is 60 minutes, the first running duration is 60 minutes.
When the client determines the second running time length by applying the timestamp, assuming that the third timestamp when the client starts to start is 6:00 and the second timestamp when the client receives the operation instruction is 6:51, determining that the second running time length is 51 minutes, and storing the second running time length into a corresponding memory; if the timestamp of the client when the client receives the operation instruction again is 7:00, determining that the second operation time length is 60 minutes, and updating the second operation time length in the memory to be 60 minutes;
when the client determines a second running time length through the application timer, when the client starts, the preset timer starts to time, when the client receives an operation instruction, the timing time length in the timer is 14 minutes, the second running time length is 14 minutes, and the second running time length is stored; and if the client receives the operation instruction again, the timing duration in the timer is 30 minutes, the second operation duration is 30 minutes, and the second operation duration stored in the corresponding memory is updated.
Assuming that the time period from the start to the reception of the operation instruction by the client is 65 minutes, the second operation time period is 65 minutes.
If the first operation time period is determined to be 60 minutes and the second operation time period is determined to be 65 minutes, the local time period is calculated to be 5 minutes.
It should be noted that the manner of determining the first operation duration and the manner of determining the second operation duration may be the same or different; when both application timestamps determine the first run-time length and the second run-time length, then the time in the first timestamp is the same as the time in the third timestamp.
In the method provided by the embodiment of the invention, the local time length of the client is determined by determining the first running time and the second running time of the client, and the time length for determining the local time length of the client can be accurate to a time unit smaller than seconds or milliseconds, so that the accuracy of the determined local time length is higher. In order to make the current time of the server calculated by the client more accurate, when calculating the current time of the server, the delay time that can join the network is calculated, and a specific process can refer to fig. 4, which is specifically described as follows:
s401, determining the average network delay time of the client.
In the method provided by the embodiment of the invention, the network delay average time of the client can be calculated, and the method for calculating the network delay average time can be calculated according to the preset calculation software in the terminal or the calculation plug-in of the client.
S402, calculating the timestamp, the local time length and the network delay average time according to a preset second algorithm to obtain the current time of the server.
In the method provided by the embodiment of the present invention, the obtained timestamp, the calculated local time length, and the network delay average duration are calculated, and the second algorithm may be: the current time of the server is the timestamp, the local time length and the network delay average time length; for example, if the timestamp is 8 points and 8 minutes, the local time length is 9 minutes, and the average network delay time is 1 second, the calculated current time of the server is 8 points and 17 points and zero for 1 second.
S403, taking the current time of the server as the current time of the client, and completing the time synchronization between the client and the server.
In the method provided by the embodiment of the present invention, the current time of the server obtained by calculation is determined as the current time of the client, and referring to S402, if the current time of the server obtained by calculation is 8 points, 17 points, and zero for 1 second, the current time of the client is determined as 8 points, 17 points, zero for 1 second; and completing the time synchronization of the client and the server.
In the method provided by the embodiment of the present invention, after the time synchronization between the client and the server is completed, it is determined whether the client can send data to the server, and the specific process is as follows:
acquiring data to be sent which needs to be sent to a server, wherein the data to be sent is data sent by a user;
determining the current time of the client and determining the preset forbidden time in the client;
and judging whether the current time of the client is greater than the forbidden time, and if the current time of the client is greater than the forbidden time, sending the data to be sent to a server.
In the method provided by the embodiment of the invention, the data sent to the server is determined to be the data which needs to be sent to the server by the user; determining preset forbidden time in the client, wherein the forbidden time is sent to the client by the server, for example, the server forbids the words of the client, the server issues forbidden time to the client, and if the forbidden time is 22 o ' clock and 5 min, the client cannot send data to the server in the period from 21 o ' clock to 22 o ' clock and 5 min; and continuing the unlocking time, and sending the data to the server by the client on the assumption that the current time of the client is 22: 6. When the current time of the client is less than or equal to the forbidden time, popping up preset prompt information to prompt that data cannot be sent to the server at present; the prompt may be preset according to a requirement, for example, the specific content may be: the talk-back time is not over. The prompting method includes but is not limited to prompting in the form of short message or pop-up window.
In the method provided by the embodiment of the invention, by applying the method provided by the invention, the current time of the server obtained by calculation can be determined as the current time of the client, so that the time synchronization of the server and the client is realized; the client processes various data requirements according to the determined current time, so that the accuracy of a processing result is improved, and the experience of a user using the client is improved.
In the method provided by the embodiment of the invention, when the client receives an operation instruction sent by a user, a pre-stored timestamp is obtained, wherein the timestamp is the server time in a data packet sent to the client by a server last time; determining the type of an application system currently operated by the client, and calculating a local time length according to a time calculation method corresponding to the type of the application system, wherein the local time length is the local time length from the time when the client receives the data packet to the time when the client receives the operation instruction; calculating the local time length and the timestamp according to a preset first algorithm to obtain the current time of the server; and taking the current time of the server as the current time of the client, and completing the time synchronization of the client and the server. By applying the invention, the server does not need to send the current time of the server to the client in real time; the client can automatically calculate the current time of the server and determine the calculated current time of the server as the current time of the client; the client can process various data requests according to the determined current time, so that the working energy consumption of the server is reduced, the data processing accuracy of the client is improved, and the use experience of a user using the client is improved.
Corresponding to fig. 1, a time synchronization apparatus is further provided in the embodiment of the present invention, which is used to support the application of the time synchronization method provided in the embodiment of the present invention in practice, the time synchronization apparatus can be applied to various computing apparatuses and intelligent devices, and a device structure diagram of the time synchronization apparatus can refer to fig. 5, which specifically describes the following:
a first obtaining unit 501, configured to obtain a timestamp that is pre-stored when the client receives an operation instruction sent by a user, where the timestamp is a server time in a data packet that is sent by a server to the client last time;
a first determining unit 502, configured to determine a type of an application system currently running by the client, and calculate a local time length according to a time calculation method corresponding to the type of the application system, where the local time length is a local time length from when the client receives the data packet to when the client receives the operation instruction;
the first calculating unit 503 is configured to calculate the local time length and the timestamp according to a preset first algorithm to obtain the current time of the server;
a first synchronization unit 504, configured to use the current time of the server as the current time of the client, and complete time synchronization between the client and the server.
In the device provided by the embodiment of the invention, when the client receives an operation instruction sent by a user, a pre-stored timestamp is obtained, wherein the timestamp is the server time in a data packet sent to the client by a server last time; determining the type of an application system currently operated by the client, and calculating a local time length according to a time calculation method corresponding to the type of the application system, wherein the local time length is the local time length from the time when the client receives the data packet to the time when the client receives the operation instruction; calculating the local time length and the timestamp according to a preset first algorithm to obtain the current time of the server; and taking the current time of the server as the current time of the client, and completing the time synchronization of the client and the server. By applying the invention, the server does not need to send the current time of the server to the client in real time; the client can automatically calculate the current time of the server and determine the calculated current time of the server as the current time of the client; the client can process various data requests according to the determined current time, so that the working energy consumption of the server is reduced, the data processing accuracy of the client is improved, and the use experience of a user using the client is improved.
In the time synchronization apparatus provided in the embodiment of the present invention, the first determining unit 502 may be configured to:
the first obtaining subunit is configured to obtain a system identifier of an application system currently running on the client, and determine a system type to which the application system belongs according to the system identifier;
the first determining subunit is configured to determine, when the application system is a first type system, a timing duration in a timer preset when the operation instruction is received, where the timer executes a zeroing operation and starts timing when the client receives a data packet sent by the server;
and the second determining subunit is configured to determine the timing duration determined in the timer as the local time length.
In the time synchronization apparatus provided in the embodiment of the present invention, the first determining unit 502 may be configured to:
the second obtaining subunit is configured to obtain a system identifier of the application system currently running on the client, and determine a system type to which the application system belongs according to the system identifier;
a third determining subunit, configured to determine, when the application system is a second type system, a first running duration, where the first running duration is a local duration from starting to receiving the data packet by the client;
a fourth determining subunit, configured to determine a second operation duration, where the second operation duration is a local duration from the start to the reception of the sending instruction by the client;
and the calculating subunit is used for substituting the second operation time length and the first operation time length into a preset calculation formula to calculate, so as to obtain an operation time difference output by the calculation formula, and determining the operation time difference as the local time length.
In the time synchronization apparatus provided in the embodiment of the present invention, the time synchronization apparatus may be further configured to:
a second determining unit, configured to determine a network delay average duration of the client;
the second calculation unit is used for calculating the timestamp, the local time length and the network delay average time length according to a preset second algorithm to obtain the current time of the server;
and the second synchronization unit is used for taking the current time of the server as the current time of the client and completing the time synchronization between the client and the server.
In the time synchronization apparatus provided in the embodiment of the present invention, the time synchronization apparatus may be further configured to:
the second acquiring unit is used for acquiring data to be sent which needs to be sent to the server, wherein the data to be sent is data sent by a user;
a third determining unit, configured to determine a current time of the client and determine a disable-release time preset in the client;
and the judging unit is used for judging whether the current time of the client is greater than the forbidden time, and if the current time of the client is greater than the forbidden time, sending the data to be sent to a server.
The embodiments in the present specification are described in a progressive manner, and the same and similar parts among the embodiments are referred to each other, and each embodiment focuses on the differences from the other embodiments. In particular, the system or system embodiments are substantially similar to the method embodiments and therefore are described in a relatively simple manner, and reference may be made to some of the descriptions of the method embodiments for related points. The above-described system and system embodiments are only illustrative, wherein the units described as separate parts may or may not be physically separate, and the parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of the present embodiment. One of ordinary skill in the art can understand and implement it without inventive effort.
Those of skill would further appreciate that the various illustrative elements and algorithm steps described in connection with the embodiments disclosed herein may be implemented as electronic hardware, computer software, or combinations of both, and that the various illustrative components and steps have been described above generally in terms of their functionality in order to clearly illustrate this interchangeability of hardware and software. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the implementation. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present invention.
The previous description of the disclosed embodiments is provided to enable any person skilled in the art to make or use the present invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the generic principles defined herein may be applied to other embodiments without departing from the spirit or scope of the invention. Thus, the present invention is not intended to be limited to the embodiments shown herein but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.
Claims (10)
1. A time synchronization method is applied to a client and comprises the following steps:
when the client receives an operation instruction sent by a user, a pre-stored time stamp is obtained, wherein the time stamp is the server time in a data packet sent to the client by a server last time;
determining the type of an application system currently operated by the client, and calculating a local time length according to a time calculation method corresponding to the type of the application system, wherein the local time length is the local time length from the time when the client receives the data packet to the time when the client receives the operation instruction;
calculating the local time length and the timestamp according to a preset first algorithm to obtain the current time of the server;
and taking the current time of the server as the current time of the client, and completing the time synchronization of the client and the server.
2. The method according to claim 1, wherein the determining the type of the application system currently running by the client and calculating the local time length according to the time calculation method corresponding to the type of the application system comprises:
acquiring a system identifier of an application system currently operated by the client, and determining a system type to which the application system belongs according to the system identifier;
when the application system is a first type system, determining the timing duration in a preset timer when the operation instruction is received, and executing a zero setting operation and starting timing when a client receives a data packet sent by the server by the timer;
and determining the timing duration determined in the timer as the local time length.
3. The method according to claim 1, wherein the determining the type of the application system currently running by the client and calculating the local time length according to the time calculation method corresponding to the type of the application system comprises:
acquiring a system identifier of an application system currently operated by the client, and determining a system type to which the application system belongs according to the system identifier;
when the application system is a second type system, determining a first operation time length, wherein the first operation time length is a local time length from the start of the client to the reception of the data packet;
determining a second operation duration, wherein the second operation duration is a local duration from the starting to the receiving of the sending instruction by the client;
substituting the second operation duration and the first operation duration into a preset calculation formula for calculation to obtain an operation time difference output by the calculation formula, and determining the operation time difference as the local time length.
4. The method of claim 1, further comprising:
determining the average network delay time of the client;
calculating the timestamp, the local time length and the network delay average time according to a preset second algorithm to obtain the current time of the server;
and taking the current time of the server as the current time of the client, and completing the time synchronization of the client and the server.
5. The method of claim 1, further comprising:
acquiring data to be sent which needs to be sent to a server, wherein the data to be sent is data sent by a user;
determining the current time of the client and determining the preset forbidden time in the client;
and judging whether the current time of the client is greater than the forbidden time, and if the current time of the client is greater than the forbidden time, sending the data to be sent to a server.
6. A time synchronization device applied to a client comprises:
the first acquisition unit is used for acquiring a pre-stored timestamp when the client receives an operation instruction sent by a user, wherein the timestamp is the server time in a data packet which is sent to the client by a server last time;
a first determining unit, configured to determine a type of an application system currently running by the client, and calculate a local time length according to a time calculation method corresponding to the type of the application system, where the local time length is a local time length from when the client receives the data packet to when the client receives the operation instruction;
the first calculating unit is used for calculating the local time length and the timestamp according to a preset first algorithm to obtain the current time of the server;
and the first synchronization unit is used for taking the current time of the server as the current time of the client and completing the time synchronization of the client and the server.
7. The apparatus of claim 6, wherein the first determining unit comprises:
the first obtaining subunit is configured to obtain a system identifier of an application system currently running on the client, and determine a system type to which the application system belongs according to the system identifier;
the first determining subunit is configured to determine, when the application system is a first type system, a timing duration in a timer preset when the operation instruction is received, where the timer executes a zeroing operation and starts timing when the client receives a data packet sent by the server;
and the second determining subunit is configured to determine the timing duration determined in the timer as the local time length.
8. The apparatus of claim 6, wherein the first determining unit comprises:
the second obtaining subunit is configured to obtain a system identifier of the application system currently running on the client, and determine a system type to which the application system belongs according to the system identifier;
a third determining subunit, configured to determine, when the application system is a second type system, a first running duration, where the first running duration is a local duration from starting to receiving the data packet by the client;
a fourth determining subunit, configured to determine a second operation duration, where the second operation duration is a local duration from the start to the reception of the sending instruction by the client;
and the calculating subunit is used for substituting the second operation time length and the first operation time length into a preset calculation formula to calculate, so as to obtain an operation time difference output by the calculation formula, and determining the operation time difference as the local time length.
9. The apparatus of claim 6, further comprising:
a second determining unit, configured to determine a network delay average duration of the client;
the second calculation unit is used for calculating the timestamp, the local time length and the network delay average time length according to a preset second algorithm to obtain the current time of the server;
and the second synchronization unit is used for taking the current time of the server as the current time of the client and completing the time synchronization between the client and the server.
10. The apparatus of claim 6, further comprising:
the second acquiring unit is used for acquiring data to be sent which needs to be sent to the server, wherein the data to be sent is data sent by a user;
a third determining unit, configured to determine a current time of the client and determine a disable-release time preset in the client;
and the judging unit is used for judging whether the current time of the client is greater than the forbidden time, and if the current time of the client is greater than the forbidden time, sending the data to be sent to a server.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201911035308.9A CN110768740B (en) | 2019-10-29 | 2019-10-29 | Time synchronization method and device |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201911035308.9A CN110768740B (en) | 2019-10-29 | 2019-10-29 | Time synchronization method and device |
Publications (2)
Publication Number | Publication Date |
---|---|
CN110768740A true CN110768740A (en) | 2020-02-07 |
CN110768740B CN110768740B (en) | 2020-12-01 |
Family
ID=69334367
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201911035308.9A Active CN110768740B (en) | 2019-10-29 | 2019-10-29 | Time synchronization method and device |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN110768740B (en) |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN115914396A (en) * | 2021-08-17 | 2023-04-04 | 多点生活(成都)科技有限公司 | Call link generation method and device, electronic equipment and computer readable medium |
Citations (7)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN102904887A (en) * | 2012-09-26 | 2013-01-30 | 东软集团股份有限公司 | Method and system for data synchronization of Web client and server |
CN103841180A (en) * | 2014-01-17 | 2014-06-04 | 北京京东尚科信息技术有限公司 | Network data synchronization method and device based on operating instruction, terminal device and server |
US20140372224A1 (en) * | 2013-06-14 | 2014-12-18 | Blue Kai, Inc. | Multi-profile tracking identification of a mobile user |
CN105765987A (en) * | 2013-09-20 | 2016-07-13 | 皇家Kpn公司 | Correlating timeline information between media streams |
CN106961377A (en) * | 2016-01-12 | 2017-07-18 | 北大方正集团有限公司 | Message synchronization method and message synchronization system |
CN107231400A (en) * | 2016-03-25 | 2017-10-03 | 阿里巴巴集团控股有限公司 | The synchronous method and device of a kind of data |
CN107852416A (en) * | 2015-08-26 | 2018-03-27 | 微软技术许可有限责任公司 | The life cycle of monitoring computer network connection |
-
2019
- 2019-10-29 CN CN201911035308.9A patent/CN110768740B/en active Active
Patent Citations (7)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN102904887A (en) * | 2012-09-26 | 2013-01-30 | 东软集团股份有限公司 | Method and system for data synchronization of Web client and server |
US20140372224A1 (en) * | 2013-06-14 | 2014-12-18 | Blue Kai, Inc. | Multi-profile tracking identification of a mobile user |
CN105765987A (en) * | 2013-09-20 | 2016-07-13 | 皇家Kpn公司 | Correlating timeline information between media streams |
CN103841180A (en) * | 2014-01-17 | 2014-06-04 | 北京京东尚科信息技术有限公司 | Network data synchronization method and device based on operating instruction, terminal device and server |
CN107852416A (en) * | 2015-08-26 | 2018-03-27 | 微软技术许可有限责任公司 | The life cycle of monitoring computer network connection |
CN106961377A (en) * | 2016-01-12 | 2017-07-18 | 北大方正集团有限公司 | Message synchronization method and message synchronization system |
CN107231400A (en) * | 2016-03-25 | 2017-10-03 | 阿里巴巴集团控股有限公司 | The synchronous method and device of a kind of data |
Non-Patent Citations (1)
Title |
---|
王兵等: "时间戳服务系统的设计与应用研究", 《网络安全技术与应用》 * |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN115914396A (en) * | 2021-08-17 | 2023-04-04 | 多点生活(成都)科技有限公司 | Call link generation method and device, electronic equipment and computer readable medium |
Also Published As
Publication number | Publication date |
---|---|
CN110768740B (en) | 2020-12-01 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US6564046B1 (en) | Method of maintaining mobile terminal synchronization during idle communication periods | |
US20070192763A1 (en) | Method and system for scheduling application of software updates | |
EP2629572B1 (en) | Method and device of data interaction | |
CN103516690A (en) | Service processing state information query method and apparatus thereof | |
JP2003087361A (en) | Mobile communication terminal | |
CN111901341B (en) | State synchronization method and device | |
CN103428844A (en) | Method for achieving mobile phone time synchronization of mobile phone terminal | |
CN103309713A (en) | System upgrading method, device and equipment | |
CN110768740B (en) | Time synchronization method and device | |
WO2013123885A1 (en) | Method and device for synchronizing alarm clock | |
US20170063985A1 (en) | Global Logical Timestamp | |
WO2021036558A1 (en) | Wireless network connection method and related apparatus | |
CN108713171A (en) | Communication equipment, communication means, communication system, electronic watch and program | |
CN108462734B (en) | Message receiving method and device | |
CN101656753B (en) | Content synchronization method, equipment and system for dynamic content delivery | |
CN111399367A (en) | Time correction method based on pigeon clock equipment, server and storage medium | |
CN103580887A (en) | Clients, updating method and updating system | |
JP6705041B2 (en) | Communication terminal, setting method and program | |
CN109714403A (en) | A kind of method and device of determining user's online time | |
CN114499816B (en) | Clock synchronization method and device, terminal equipment and readable storage medium | |
CN103973804B (en) | Method and device for setting terminal time | |
CN112667255B (en) | Updating method, updating device, electronic equipment and storage medium | |
CN115347970A (en) | Clock synchronization method, device and equipment of electric power real-time simulation system | |
CN114222148A (en) | Countdown control method and device, storage medium and computer equipment | |
CN109510682B (en) | Method, device, terminal and storage medium for synchronizing BMC (baseboard management controller) clocks of pooling server system |
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 |