CN119154985A - Time synchronization method, terminal and computer readable storage medium - Google Patents
- ️Tue Dec 17 2024
CN119154985A - Time synchronization method, terminal and computer readable storage medium - Google Patents
Time synchronization method, terminal and computer readable storage medium Download PDFInfo
-
Publication number
- CN119154985A CN119154985A CN202411598005.9A CN202411598005A CN119154985A CN 119154985 A CN119154985 A CN 119154985A CN 202411598005 A CN202411598005 A CN 202411598005A CN 119154985 A CN119154985 A CN 119154985A Authority
- CN
- China Prior art keywords
- time
- ntp server
- client
- reply message
- request message Prior art date
- 2024-11-11 Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
- 238000000034 method Methods 0.000 title claims abstract description 145
- 230000004044 response Effects 0.000 claims abstract description 107
- 238000004891 communication Methods 0.000 claims abstract description 16
- 230000008569 process Effects 0.000 claims description 76
- 238000004590 computer program Methods 0.000 claims description 9
- 238000012937 correction Methods 0.000 claims description 4
- 230000005540 biological transmission Effects 0.000 description 17
- 238000010586 diagram Methods 0.000 description 10
- 230000003993 interaction Effects 0.000 description 9
- 238000012545 processing Methods 0.000 description 4
- 230000008878 coupling Effects 0.000 description 3
- 238000010168 coupling process Methods 0.000 description 3
- 238000005859 coupling reaction Methods 0.000 description 3
- 238000005516 engineering process Methods 0.000 description 2
- 230000009471 action Effects 0.000 description 1
- 238000004364 calculation method Methods 0.000 description 1
- 238000007796 conventional method Methods 0.000 description 1
- 239000013078 crystal Substances 0.000 description 1
- 230000006870 function Effects 0.000 description 1
- 230000003287 optical effect Effects 0.000 description 1
- 230000001360 synchronised effect Effects 0.000 description 1
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
- H04J3/0658—Clock or time synchronisation among packet nodes
- H04J3/0661—Clock or time synchronisation among packet nodes using timestamps
- H04J3/0667—Bidirectional timestamps, e.g. NTP or PTP for compensation of clock drift and for compensation of propagation delays
-
- 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)
- Synchronisation In Digital Transmission Systems (AREA)
Abstract
The application provides a time synchronization method, a terminal and a computer readable storage medium, wherein the time synchronization method comprises a client and an NTP server, wherein the client is in communication connection with the NTP server, and the client sends a generated request message to the NTP server; the method comprises the steps of receiving a reply message containing response time and made by an NTP server based on a request message and sending time of the reply message sent by the NTP server, determining current compensation time based on the response time and the sending time, and adjusting a clock of a client based on the current compensation time. According to the application, the problem of time delay is caused by considering the inconsistent response time in the reply message and the sending time of the reply message, so that the current compensation time is determined by the response time and the sending time of the reply message, and then the clock of the client is compensated according to the current compensation time, thereby improving the time synchronization accuracy of the NTP of the client.
Description
Technical Field
The present invention relates to the field of network communications technologies, and in particular, to a time synchronization method, a terminal, and a computer readable storage medium.
Background
There may be multiple devices within the same lan operating simultaneously, during which there is a continuous need for protocol interaction, which requires time consistency and accuracy between the devices. Because the time crystal oscillator specifications of the equipment are different, errors are gradually accumulated and increased along with the time, and time synchronization is needed. Currently, NTP (Network Time Protocol ) technology is mainly adopted to solve the clock synchronization problem of the current internet, and network time protocol (Network Time Protocol, NTP) is a time synchronization service protocol, and aims to provide uniform time synchronization service for devices running on a network. The conventional method for realizing network time synchronization is that a computer in a network sends and receives an NTP protocol data packet with a time stamp, then calculates the current time difference according to the time stamp data carried by the NTP protocol data packet, then compensates the current time difference by taking the current time of the system, and then sets the current time difference to the system to synchronize the own time with the standard time.
Disclosure of Invention
The invention mainly solves the technical problem of providing a time synchronization method, a terminal and a computer readable storage medium, and solves the problem of poor timing precision of NTP (network time protocol) of a client in the prior art.
In order to solve the technical problems, the first technical scheme adopted by the invention is to provide a time synchronization method, which comprises a client and an NTP server, wherein the client is in communication connection with the NTP server and comprises the following steps:
The client sends the generated request message to an NTP server;
Receiving a reply message containing response time and made by the NTP server based on the request message, and sending time of the reply message sent by the NTP server;
determining a current compensation time based on the response time and the transmission time;
the clock of the client is adjusted based on the current backoff time.
The receiving the reply message including the response time and the sending time of the reply message sent by the NTP server based on the request message comprises the following steps:
Receiving a reply message containing response time and made based on a request message in the current time synchronization process and the time for the NTP server to receive the request message, wherein the reply message is sent by the NTP server;
Receiving the sending time of a reply message in the current time synchronization process sent by the NTP server;
Determining a current compensation time based on the response time and the transmission time, comprising:
and determining the current compensation time based on the response time in the reply message and the sending time of the reply message in the current time synchronization process.
The receiving the reply message including the response time and the sending time of the reply message sent by the NTP server based on the request message comprises the following steps:
receiving a reply message containing response time and made based on a request message in the current time synchronization process sent by an NTP (network time protocol) server, the time for the NTP server to receive the request message and the sending time for the NTP server to send a history reply message in the history time synchronization process;
Determining a current compensation time based on the response time and the transmission time, comprising:
And determining the current compensation time based on the sending time of the historical reply message sent by the NTP server in the same historical time synchronization process and the historical response time contained in the historical reply message.
The method for receiving the response message containing response time and made based on the request message in the current time synchronization process sent by the NTP server, the time for the NTP server to receive the request message and the sending time for the NTP server to send the historical response message in the historical time synchronization process comprise the following steps:
Receiving a reply message containing response time and made based on a request message in the current time synchronization process sent by an NTP server, the time for the NTP server to receive the request message and the sending time of a history reply message sent by the NTP server in the adjacent previous time synchronization process;
determining the current compensation time based on the sending time of the historical reply message sent by the NTP server in the same historical time synchronization process and the historical response time contained in the historical reply message comprises the following steps:
And determining the current compensation time based on the sending time of the historical reply message sent by the NTP server in the adjacent previous time synchronization process and the historical response time contained in the historical reply message.
Wherein the transmission time is not later than the response time,
Determining a current compensation time based on the response time and the transmission time, comprising:
half of the difference between the transmission time and the response time is determined as the current compensation time.
The method for adjusting the clock of the client based on the current compensation time comprises the following steps:
Determining the initial time of the client based on the time of the client sending the request message, the time of the NTP server receiving the request message, the response time of the NTP server and the time of the client receiving the reply message;
and adding the current compensation time and the initial time of the client to obtain the correction time of the client.
In order to solve the technical problems, the second technical scheme adopted by the invention is to provide a time synchronization method, which comprises a client and an NTP server, wherein the client is in communication connection with the NTP server and comprises the following steps:
The NTP server receives a request message generated and sent by the client;
The NTP server responds to the request message and sends the response time as a reply message and the sending time of the reply message to the client, so that the client determines the current compensation time based on the response time and the sending time, and the clock of the client is adjusted through the current compensation time.
The NTP server responds to the request message and sends the response time as a reply message and the sending time of the reply message to the client, and the NTP server comprises:
the NTP server responds to the request message and takes the response time as a reply message;
the NTP server side sends the time for receiving the request message and the reply message to the client side;
After the reply message is sent out, the NTP server side sends the sending time of the reply message to the client side.
The NTP server responds to the request message and sends the response time as a reply message and the sending time of the reply message to the client, and the NTP server comprises:
The NTP server responds to the request message in the current time synchronization process, and takes the response time as a reply message;
The NTP server sends the time for receiving the request message in the current time synchronization process, the reply message and the sending time of the reply message in the history time synchronization process to the client.
In order to solve the technical problem, a third technical scheme adopted by the invention is to provide a terminal, wherein the terminal comprises a memory, a processor and a computer program stored in the memory and running on the processor, and the processor is used for executing program data to realize the steps in the time synchronization method.
In order to solve the technical problem, a fourth technical scheme adopted by the invention is to provide a computer readable storage medium, wherein a computer program is stored on the computer readable storage medium, and the steps in the time synchronization method are realized when the computer program is executed by a processor.
The time synchronization method, the terminal and the computer readable storage medium have the advantages that the time synchronization method, the terminal and the computer readable storage medium are different from the situation of the prior art, the time synchronization method comprises the steps that a client and an NTP server are connected in a communication mode, the client sends a generated request message to the NTP server, the NTP server receives a response message containing response time and the sending time of the response message sent by the NTP server based on the request message, the current compensation time is determined based on the response time and the sending time, and the clock of the client is adjusted based on the current compensation time. According to the application, the problem of time delay is caused by considering the inconsistent response time in the reply message and the sending time of the reply message, so that the current compensation time is determined by the response time and the sending time of the reply message, and then the clock of the client is compensated according to the current compensation time, thereby improving the time synchronization accuracy of the NTP of the client.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings required for the description of the embodiments will be briefly described below, and it is apparent that the drawings in the following description are only some embodiments of the present invention, and other drawings may be obtained according to these drawings without inventive effort for a person skilled in the art.
FIG. 1 is a schematic diagram of information interaction of a time synchronization method provided in the prior art;
Fig. 2 is a flow chart of a time synchronization method of a client provided by the invention;
FIG. 3 is a schematic flow chart of a method for time synchronization of a server side according to the present invention;
FIG. 4 is a schematic diagram illustrating information interaction of an embodiment of a time synchronization method according to the present invention;
FIG. 5 is a schematic diagram of information interaction of another embodiment of the time synchronization method provided by the present invention;
FIG. 6 is a schematic diagram of a frame of an embodiment of a terminal provided by the present invention;
FIG. 7 is a schematic diagram of a computer-readable storage medium according to an embodiment of the present invention.
Detailed Description
The following describes embodiments of the present application in detail with reference to the drawings.
In the following description, for purposes of explanation and not limitation, specific details are set forth such as the particular system architecture, interfaces, techniques, etc., in order to provide a thorough understanding of the present application.
The term "and/or" is merely an association relationship describing the associated object, and means that three relationships may exist, for example, a and/or B may mean that a exists alone, while a and B exist together, and B exists alone. In addition, the character "/" herein generally indicates that the front and rear associated objects are an "or" relationship. Further, "a plurality" herein means two or more than two.
In order to enable those skilled in the art to better understand the technical solution of the present invention, a time synchronization method provided by the present invention is described in further detail below with reference to the accompanying drawings and the detailed description.
Unless defined otherwise, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs. The terminology used herein is for the purpose of describing embodiments of the application only and is not intended to be limiting of the application.
The time synchronization method provided by the embodiment of the application can be independently implemented by the client or the server or cooperatively implemented by the server and the terminal. In some embodiments, the terminal or the server may implement the time synchronization method provided by the embodiments of the present application by running a computer program. For example, the computer program may be a Native program or a software module in an operating system, a Native Application (APP), i.e., a program that needs to be installed in the operating system to run, such as a client that supports a virtual scenario, such as a game APP, an applet, i.e., a program that needs to be downloaded only to a browser environment to run, or an applet that can be embedded in any APP. In general, the computer programs described above may be any form of application, module or plug-in.
Referring to fig. 1, fig. 1 is a schematic information interaction diagram of a time synchronization method provided in the prior art.
The current NTP protocol flow realizes time synchronization of the client and the NTP server, and the client sends an NTP request message to the NTP server, wherein the NTP request message comprises a time stamp T1 of the message leaving the client. The NTP server receives the NTP request message, and the timestamp of the NTP request message received by the NTP server is T2. The NTP server processes the received NTP request message to obtain a reply message, wherein the reply message comprises a time T3 during processing. The NTP server sends the reply message and the timestamp of the NTP request message received by the NTP server is T2, and the timestamp of the NTP request message leaving the client is T1, and the timestamp of the reply message received by the client is T4.
The client calculates a Delay time Delay from the client to the NTP server and a time difference offset between the client and the NTP server based on a time stamp T1 of the NTP request message leaving the client, a time stamp T2 of the NTP request message received by the NTP server, a time stamp T3 of the reply message received by the client and a time stamp T4 of the reply message received by the client.
Specifically, the Delay time Delay from the client to the NTP server of the NTP request message is calculated based on the following formula.
Delay= ((T4-T1) - (T3-T2))/2 (formula 1)
Specifically, the time difference Offset between the client and the NTP server is calculated based on the following formula.
Offset= ((T2-T1) + (T3-T4))/2 (equation 2)
Specifically, the client corrected Time Current Time is calculated based on the following formula.
Current Time=T4+ offset=t3+delay= (T4+T3+T2-T1)/2 (equation 3)
The field of the proposal is an embedded device NTP time synchronization process. The traditional NTP time service is to mark a time stamp after an application layer analyzes an NTP message, and the software time stamp has larger error in precision due to uncertainty of software execution, and the problem is one of main reasons for increasing the NTP time correction error. Specifically, the time of the reply message generated by the NTP server is inconsistent with the time of the NTP server for sending the reply message, specifically, the time of the NTP server for sending the reply message is later than the time of the reply message, so that the time error of the NTP is increased.
The time synchronization method provided by the embodiment considers that the time of the reply message generated by the NTP server is inconsistent with the time of the reply message sent by the NTP server, and corrects the time of the client based on the difference between the time of the reply message sent and the time of the generated reply message.
The time synchronization method provided by the embodiment is suitable for a relatively stable local area network environment, and the accuracy of time synchronization on the client and the NTP server is better through the time synchronization method provided by the embodiment.
Referring to fig. 2, fig. 2 is a flowchart of a time synchronization method of a client according to the present invention.
The embodiment provides a time synchronization method, which comprises a client and an NTP server, wherein the client is in communication connection with the NTP server. The execution subject of the time synchronization method in this embodiment is a client. The time synchronization method includes the following steps.
And S11, the client sends the generated request message to the NTP server.
S12, receiving a reply message containing response time and made by the NTP server based on the request message and the sending time of the reply message sent by the NTP server.
And S13, determining the current compensation time based on the response time and the sending time.
And S14, adjusting the clock of the client based on the current compensation time.
In an embodiment, the client sends the generated request message to the NTP server, where the request message carries a timestamp of the client sending the request message.
In an embodiment, the current backoff time is determined based on the response time and the transmission time in the current time synchronization process.
Specifically, in step S12, specific embodiments of a reply message including response time and a sending time of the NTP server for sending the reply message, which are made by the NTP server based on the request message, are as follows.
Receiving a reply message containing response time and made by a request message in the current time synchronization process sent by the NTP server and the time for the NTP server to receive the request message, and receiving the sending time of the reply message in the current time synchronization process sent by the NTP server.
Specifically, the specific embodiment of determining the current compensation time based on the response time and the transmission time in step S13 is as follows.
And determining the current compensation time based on the response time in the reply message and the sending time of the reply message in the current time synchronization process.
Because the NTP server cannot send the sending time of the NTP server at the same time of sending the reply message, the time of sending the reply message is required to be sent to the client. The present embodiment provides two methods of determining the current compensation time.
In an embodiment, the current compensation time is determined based on a response time and a transmission time in a historical time synchronization process prior to the current time synchronization process.
Specifically, in step S12, specific embodiments of a reply message including response time and a sending time of the NTP server for sending the reply message, which are made by the NTP server based on the request message, are as follows.
Receiving a reply message containing response time and made based on a request message in the current time synchronization process sent by the NTP server, the time for the NTP server to receive the request message, and the sending time of the history reply message sent by the NTP server in the history time synchronization process.
In a specific embodiment, a reply message including response time and made based on a request message in a current time synchronization process and sent by an NTP server is received, and the time of the NTP server receiving the request message and the sending time of an NTP server sending a history reply message in a neighboring previous time synchronization process are received.
Specifically, the specific embodiment of determining the current compensation time based on the response time and the transmission time in step S13 is as follows.
And determining the current compensation time based on the sending time of the historical reply message sent by the NTP server in the same historical time synchronization process and the historical response time contained in the historical reply message.
In a specific embodiment, in order to improve the accuracy of time synchronization, since the time synchronization method provided in the embodiment is suitable for a scenario where a local area network is stable, the clock of the client in the current time synchronization process may be adjusted based on the historical compensation time determined by the historical response time and the historical transmission time in the historical time synchronization process closest to the current time synchronization process. Because the local area network is stable, the difference between the compensation time in the previous time synchronization process and the compensation time in the current time synchronization process is not large, and the compensation time in the previous time synchronization process can be used as the current compensation time in the current time synchronization process, so that the accuracy of the time synchronization of the client is improved.
And determining the current compensation time based on the sending time of the historical reply message sent by the NTP server in the adjacent previous time synchronization process and the historical response time contained in the historical reply message.
Specifically, the specific embodiment of adjusting the clock of the client based on the current compensation time in step S14 is as follows.
In one embodiment, the initial time of the client is determined based on the time when the client sends the request message, the time when the NTP server receives the request message, the response time of the NTP server, and the time when the client receives the response message, and the current compensation time and the initial time of the client are summed to obtain the correction time of the client.
The time synchronization method comprises a client and an NTP server, wherein the client is in communication connection with the NTP server, the method comprises the steps of sending a generated request message to the NTP server by the client, receiving a response message containing response time and made by the NTP server based on the request message, and sending time of the response message sent by the NTP server, determining current compensation time based on the response time and the sending time, and adjusting a clock of the client based on the current compensation time. According to the application, the problem of time delay is caused by considering the inconsistent response time in the reply message and the sending time of the reply message, so that the current compensation time is determined by the response time and the sending time of the reply message, and then the clock of the client is compensated according to the current compensation time, thereby improving the time synchronization accuracy of the NTP of the client.
Referring to fig. 3, fig. 3 is a flowchart of a time synchronization method of a server provided by the present invention.
The embodiment provides a time synchronization method, which comprises a client and an NTP server, wherein the client is in communication connection with the NTP server. In this embodiment, the execution body of the time synchronization method is an NTP server. The time synchronization method includes the following steps.
S21, the NTP server receives the request message generated and sent by the client.
And S22, the NTP server responds to the request message, and sends the response time as a reply message and the sending time of the reply message to the client, so that the client determines the current compensation time based on the response time and the sending time, and the clock of the client is adjusted through the current compensation time.
Specifically, in step S22, the specific implementation manner in which the NTP server responds to the request message and sends the response time as the reply message and the sending time of the reply message to the client is as follows.
In one embodiment, the NTP server responds to the request message and takes the response time as a reply message, the NTP server sends the time for receiving the request message and the reply message to the client, and the NTP server sends the sending time of the reply message to the client after the reply message is sent.
In another embodiment, the NTP server responds to the request message in the current time synchronization process and takes the response time as a reply message, and the NTP server sends the time for receiving the request message in the current time synchronization process, the reply message and the sending time of the reply message in the history time synchronization process to the client.
According to the application, the problem of time delay is caused by considering the inconsistent response time in the reply message and the sending time of the reply message, so that the current compensation time is determined by the response time and the sending time of the reply message, and then the clock of the client is compensated according to the current compensation time, thereby improving the time synchronization accuracy of the NTP of the client.
Referring to fig. 4, fig. 4 is an information interaction schematic diagram of an embodiment of a time synchronization method according to the present invention.
In a specific embodiment, the time synchronization method determines the current compensation time based on the response time and the transmission time in the current time synchronization process.
Specifically, the client sends the generated request message to an NTP server, the request message carries a timestamp T1 of the request message sent by the client, the NTP server receives the request message sent by the client, the timestamp of the request message sent by the client is T2, and the NTP server responds to the request message and generates a reply message containing response time. Wherein, the response time in the reply message is T3. The NTP server sends the reply message, the timestamp T1 of the client sending the request message and the timestamp T2 of the client receiving the request message to the client, and the timestamp of the NTP server sending the reply message to the client is T3'. The client receives the reply message, the timestamp T1 of the client sending the request message and the timestamp T2 of the NTP server receiving the request message, and the timestamp T4 of the timestamp T1 of the client sending the request message and the timestamp T2 of the NTP server receiving the request message. The NTP server continues to send the ACK message carrying the timestamp T3 ́ that the NTP server sent the reply message to the client. The time for the NTP server to send the timestamp T3' to the client is T5. The client receives an ACK message with a timestamp T3' which carries the timestamp T6 of the response message sent to the client by the NTP server, and the timestamp is T6.
Specifically, the current compensation time Δt is determined based on the response time and the transmission time in the current time synchronization process.
Δt= (T3 ́ -T3)/2 (formula 4)
Specifically, when the client receives the time T6 ́ carrying the ACK message of the timestamp T3' that the NTP server sends the reply message to the client, the current time T6 ́ is obtained by correcting the time terminal of the client based on the current compensation time Δt in the current time synchronization process.
T6 ́ =t6+ DeltaT (equation 5)
The method can compensate the current time when the system is set at the time T6, so that the time of the client is consistent with the time of the NTP server, the NTP timing precision is improved, the added ACK message resource cost is small, the influence on the system performance and the memory cost are almost not counted, the accuracy of the time stamp of each time node is improved by means of the hardware time stamp, and the uncertainty of the software time stamp in the operation process is solved.
Referring to fig. 5, fig. 5 is an information interaction schematic diagram of another embodiment of the time synchronization method provided by the present invention.
In a specific embodiment, the time synchronization method determines the current compensation time based on a response time and a transmission time in a historical time synchronization process prior to the current time synchronization process.
Specifically, in the current time synchronization process, the client sends the generated request message to the NTP server, the request message carries a timestamp T n+1 1 of the request message sent by the client, the NTP server receives the request message sent by the client, the timestamp of the request message sent by the client is T n+1 2, and the NTP server responds to the request message and generates a reply message containing response time. The response time in the reply message is T n+1. The NTP server sends the reply message, the timestamp T n+1 1 of the client sending the request message and the timestamp T n+1 2 of the client receiving the request message to the client, and the timestamp T n' of the reply message sent to the client in the historical time synchronization process before the current time synchronization process is sent by the NTP server. The client receives the reply message, the timestamp T n+1 ' of the client sending the request message and the timestamp T n+1 2 of the NTP server receiving the request message are sent to the client, and the timestamp T n+1 ' of the timestamp T n ' of the reply message sent to the client in the historical time synchronization process before the current time synchronization process is sent to the client by the NTP server.
Specifically, the current compensation time Δt is determined based on the response time and the transmission time in the history time synchronization process before the current time synchronization process.
Δt= (T n3´-Tn 3)/2 (formula 6)
Specifically, when the client receives the reply message, the timestamp T n+1 1 of the client sending the request message, and the timestamp T n+1 2 of the NTP server receiving the request message are sent to the client, the NTP server corrects the time of the client to obtain the current time T n+1 4 ́ based on the current compensation time Δt corresponding to the historical time synchronization process before the current time synchronization process when the timestamp T n+1 of the timestamp T n' of the reply message sent to the client in the historical time synchronization process before the current time synchronization process.
T n+14´=(Tn+13+Tn+14-Tn+11+Tn+1 2)/2+DeltaT (equation 7)
In this embodiment, during the n+1th time synchronization process, the reply message carries the compensation time in the n time synchronization process, and the clock of the client in the n+1th time synchronization process is compensated based on the compensation time in the n time synchronization process, so as to improve the NTP time synchronization precision. Firstly, the traditional NTP interaction is completed, the synchronous time is set to the system, then the error compensation action is carried out, the situation that the time cannot be corrected due to the fault of the error calculation process is avoided, more accurate time stamp information is obtained under the condition that the NTP message interaction flow is not modified, and the precision of the NTP is greatly improved.
Referring to fig. 6, fig. 6 is a schematic diagram of a frame of an embodiment of a terminal according to the present invention. The terminal 80 comprises a memory 81 and a processor 82 coupled to each other, the processor 82 being adapted to execute program instructions stored in the memory 81 for implementing the steps of any of the time synchronization method embodiments described above. In a specific implementation scenario, the terminal 80 may include, but is not limited to, a microcomputer, a server, and further, the terminal 80 may also include a mobile device such as a notebook computer, a tablet computer, etc., which is not limited herein.
In particular, the processor 82 is operative to control itself and the memory 81 to implement the steps of any of the time synchronization method embodiments described above. The processor 82 may also be referred to as a CPU (Central Processing Unit ). The processor 82 may be an integrated circuit chip having signal processing capabilities. The Processor 82 may also be a general purpose Processor, a digital signal Processor (DIGITAL SIGNAL Processor, DSP), an Application SPECIFIC INTEGRATED Circuit (ASIC), a Field-Programmable gate array (Field-Programmable GATE ARRAY, FPGA) or other Programmable logic device, a discrete gate or transistor logic device, a discrete hardware component. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like. In addition, the processor 82 may be commonly implemented by an integrated circuit chip.
The above scheme, a time synchronization method, including a client and an NTP server, where the client is in communication connection with the NTP server, includes:
The client sends the generated request message to an NTP server;
Receiving a reply message containing response time and made by the NTP server based on the request message, and sending time of the reply message sent by the NTP server;
determining a current compensation time based on the response time and the transmission time;
the clock of the client is adjusted based on the current backoff time.
Or, a time synchronization method includes a client and an NTP server, and the communication connection between the client and the NTP server includes:
The NTP server receives a request message generated and sent by the client;
The NTP server responds to the request message and sends the response time as a reply message and the sending time of the reply message to the client, so that the client determines the current compensation time based on the response time and the sending time, and the clock of the client is adjusted through the current compensation time.
Referring to fig. 7, fig. 7 is a schematic diagram of a frame of an embodiment of a computer readable storage medium according to the present invention. The computer readable storage medium 90 stores program instructions 901 executable by a processor, the program instructions 901 for implementing the steps of any of the time synchronization method embodiments described above.
The above scheme, a time synchronization method, including a client and an NTP server, where the client is in communication connection with the NTP server, includes:
The client sends the generated request message to an NTP server;
Receiving a reply message containing response time and made by the NTP server based on the request message, and sending time of the reply message sent by the NTP server;
determining a current compensation time based on the response time and the transmission time;
the clock of the client is adjusted based on the current backoff time.
Or, a time synchronization method includes a client and an NTP server, and the communication connection between the client and the NTP server includes:
The NTP server receives a request message generated and sent by the client;
The NTP server responds to the request message and sends the response time as a reply message and the sending time of the reply message to the client, so that the client determines the current compensation time based on the response time and the sending time, and the clock of the client is adjusted through the current compensation time.
In some embodiments, functions or modules included in an apparatus provided by the embodiments of the present disclosure may be used to perform a method described in the foregoing method embodiments, and specific implementations thereof may refer to descriptions of the foregoing method embodiments, which are not repeated herein for brevity.
The foregoing description of various embodiments is intended to highlight differences between the various embodiments, which may be the same or similar to each other by reference, and is not repeated herein for the sake of brevity.
In the several embodiments provided in the present application, it should be understood that the disclosed method and apparatus may be implemented in other manners. For example, the apparatus embodiments described above are merely illustrative, e.g., the division of modules or units is merely a logical functional division, and there may be additional divisions of actual implementation, e.g., units or components may be combined or integrated into another system, or some features may be omitted, or not performed. Alternatively, the coupling or direct coupling or communication connection shown or discussed with each other may be an indirect coupling or communication connection via some interfaces, devices or units, which may be in electrical, mechanical, or other forms.
In addition, each functional unit in the embodiments of the present application may be integrated in one processing unit, or each unit may exist alone physically, or two or more units may be integrated in one unit. The integrated units may be implemented in hardware or in software functional units.
The integrated units, if implemented in the form of software functional units and sold or used as stand-alone products, may be stored in a computer readable storage medium. Based on such understanding, the technical solution of the present application may be embodied essentially or partly in the form of a software product or all or part of the technical solution, which is stored in a storage medium, and includes several instructions to cause a computer device (which may be a personal computer, a server, or a network device, etc.) or a processor (processor) to perform all or part of the steps of the methods according to the embodiments of the present application. The storage medium includes a U disk, a removable hard disk, a Read-Only Memory (ROM), a random access Memory (RAM, random Access Memory), a magnetic disk, an optical disk, or other various media capable of storing program codes.
The foregoing is only the embodiments of the present invention, and therefore, the patent protection scope of the present invention is not limited thereto, and all equivalent structures or equivalent flow changes made by the content of the present specification and the accompanying drawings, or direct or indirect application in other related technical fields, are included in the patent protection scope of the present invention.
Claims (11)
1.一种时间同步方法,其特征在于,包括客户端和NTP服务端,所述客户端与所述NTP服务端之间通信连接,包括:1. A time synchronization method, characterized in that it includes a client and an NTP server, wherein the client and the NTP server are connected in communication, including: 所述客户端将生成的请求报文发送到所述NTP服务端;The client sends the generated request message to the NTP server; 接收所述NTP服务端基于所述请求报文做出的包含响应时间的回复报文以及所述NTP服务端发送所述回复报文的发送时间;Receiving a reply message including a response time and a sending time of the reply message made by the NTP server based on the request message; 基于所述响应时间以及所述发送时间,确定当前补偿时间;Determine a current compensation time based on the response time and the sending time; 基于所述当前补偿时间对所述客户端的时钟进行调整。The clock of the client is adjusted based on the current compensation time. 2.根据权利要求1所述的时间同步方法,其特征在于,2. The time synchronization method according to claim 1, characterized in that: 所述接收所述NTP服务端基于所述请求报文做出的包含响应时间的回复报文以及所述NTP服务端发送所述回复报文的发送时间,包括:The receiving a reply message including a response time made by the NTP server based on the request message and the sending time of the reply message sent by the NTP server includes: 接收所述NTP服务端发送的基于当前时间同步过程中所述请求报文做出的包含响应时间的回复报文以及所述NTP服务端接收所述请求报文的时间;Receiving a reply message including a response time and a time when the NTP server receives the request message, sent by the NTP server based on the request message in the current time synchronization process; 接收所述NTP服务端发送的当前时间同步过程中所述回复报文的发送时间;Receive the sending time of the reply message during the current time synchronization process sent by the NTP server; 所述基于所述响应时间以及所述发送时间,确定当前补偿时间,包括:The determining the current compensation time based on the response time and the sending time includes: 基于当前时间同步过程中所述回复报文中的所述响应时间以及所述回复报文的发送时间,确定所述当前补偿时间。The current compensation time is determined based on the response time in the reply message and the sending time of the reply message during the current time synchronization process. 3.根据权利要求1所述的时间同步方法,其特征在于,3. The time synchronization method according to claim 1, characterized in that: 所述接收所述NTP服务端基于所述请求报文做出的包含响应时间的回复报文以及所述NTP服务端发送所述回复报文的发送时间,包括:The receiving a reply message including a response time made by the NTP server based on the request message and the sending time of the reply message sent by the NTP server includes: 接收所述NTP服务端发送的基于当前时间同步过程中的所述请求报文做出的包含响应时间的回复报文、所述NTP服务端接收所述请求报文的时间以及历史时间同步过程中的所述NTP服务端发送历史回复报文的发送时间;Receive a reply message including a response time sent by the NTP server based on the request message in the current time synchronization process, the time when the NTP server receives the request message, and the sending time of the historical reply message sent by the NTP server in the historical time synchronization process; 所述基于所述响应时间以及所述发送时间,确定当前补偿时间,包括:The determining the current compensation time based on the response time and the sending time includes: 基于同一历史时间同步过程中的所述NTP服务端发送所述历史回复报文的发送时间以及所述历史回复报文包含的历史响应时间,确定当前补偿时间。The current compensation time is determined based on the sending time of the historical reply message sent by the NTP server in the same historical time synchronization process and the historical response time included in the historical reply message. 4.根据权利要求3所述的时间同步方法,其特征在于,4. The time synchronization method according to claim 3, characterized in that: 所述接收所述NTP服务端发送的基于当前时间同步过程中的所述请求报文做出的包含响应时间的回复报文、所述NTP服务端接收所述请求报文的时间以及历史时间同步过程中的所述NTP服务端发送历史回复报文的发送时间,包括:The receiving of a reply message including a response time sent by the NTP server based on the request message in the current time synchronization process, the time when the NTP server receives the request message, and the sending time of the historical reply message sent by the NTP server in the historical time synchronization process, includes: 接收所述NTP服务端发送的基于当前时间同步过程中的所述请求报文做出的包含响应时间的回复报文、所述NTP服务端接收所述请求报文的时间以及相邻前一时间同步过程中的所述NTP服务端发送历史回复报文的发送时间;Receive a reply message including a response time, a time when the NTP server receives the request message, and a sending time of a historical reply message sent by the NTP server in an adjacent previous time synchronization process, sent by the NTP server based on the request message in the current time synchronization process; 所述基于同一历史时间同步过程中的所述NTP服务端发送所述历史回复报文的发送时间以及所述历史回复报文包含的历史响应时间,确定当前补偿时间,包括:The determining of the current compensation time based on the sending time of the historical reply message sent by the NTP server in the same historical time synchronization process and the historical response time included in the historical reply message includes: 基于相邻前一时间同步过程中的所述NTP服务端发送历史回复报文的发送时间以及所述历史回复报文包含的历史响应时间,确定当前补偿时间。The current compensation time is determined based on the sending time of the historical reply message sent by the NTP server in the adjacent previous time synchronization process and the historical response time included in the historical reply message. 5.根据权利要求1所述的时间同步方法,其特征在于,所述发送时间不晚于所述响应时间,5. The time synchronization method according to claim 1, wherein the sending time is no later than the response time. 所述基于所述响应时间以及所述发送时间,确定当前补偿时间,包括:The determining the current compensation time based on the response time and the sending time includes: 将所述发送时间与所述响应时间之间差值的一半,确定为所述当前补偿时间。Half of the difference between the sending time and the response time is determined as the current compensation time. 6.根据权利要求1所述的时间同步方法,其特征在于,6. The time synchronization method according to claim 1, characterized in that: 所述基于所述当前补偿时间对所述客户端的时钟进行调整,包括:The adjusting the clock of the client based on the current compensation time includes: 基于所述客户端发送所述请求报文的时间、所述NTP服务端接收所述请求报文的时间、所述NTP服务端的响应时间以及所述客户端接收所述回复报文的时间,确定所述客户端的初始时间;Determine the initial time of the client based on the time when the client sends the request message, the time when the NTP server receives the request message, the response time of the NTP server, and the time when the client receives the reply message; 将所述当前补偿时间与所述客户端的初始时间进行加和,得到所述客户端的校正时间。The current compensation time is added to the initial time of the client to obtain the correction time of the client. 7.一种时间同步方法,其特征在于,包括客户端和NTP服务端,所述客户端与所述NTP服务端之间通信连接,包括:7. A time synchronization method, characterized in that it includes a client and an NTP server, wherein the client and the NTP server are connected in communication, including: 所述NTP服务端接收所述客户端生成并发送的请求报文;The NTP server receives the request message generated and sent by the client; 所述NTP服务端响应于所述请求报文,并将响应时间作为回复报文以及所述回复报文的发送时间发送给所述客户端,以使所述客户端基于所述响应时间和所述发送时间确定当前补偿时间,通过所述当前补偿时间对所述客户端的时钟进行调整。The NTP server responds to the request message and sends the response time as a reply message and the sending time of the reply message to the client, so that the client determines the current compensation time based on the response time and the sending time, and adjusts the client's clock according to the current compensation time. 8.根据权利要求7所述的时间同步方法,其特征在于,8. The time synchronization method according to claim 7, characterized in that: 所述NTP服务端响应于所述请求报文,并将响应时间作为回复报文以及所述回复报文的发送时间发送给所述客户端,包括:The NTP server responds to the request message and sends the response time as a reply message and the sending time of the reply message to the client, including: 所述NTP服务端响应于所述请求报文,将所述响应时间作为所述回复报文;The NTP server responds to the request message and uses the response time as the reply message; 所述NTP服务端将接收所述请求报文的时间、所述回复报文发送给所述客户端;The NTP server sends the time of receiving the request message and the reply message to the client; 待所述回复报文发出后,所述NTP服务端将所述回复报文的发送时间发送给所述客户端。After the reply message is sent, the NTP server sends the sending time of the reply message to the client. 9.根据权利要求7所述的时间同步方法,其特征在于,9. The time synchronization method according to claim 7, characterized in that: 所述NTP服务端响应于所述请求报文,并将响应时间作为回复报文以及所述回复报文的发送时间发送给所述客户端,包括:The NTP server responds to the request message and sends the response time as a reply message and the sending time of the reply message to the client, including: 所述NTP服务端响应于当前时间同步过程中的所述请求报文,将所述响应时间作为所述回复报文;The NTP server responds to the request message in the current time synchronization process and uses the response time as the reply message; 所述NTP服务端将当前时间同步过程中接收所述请求报文的时间、所述回复报文以及历史时间同步过程中所述回复报文的发送时间发送给所述客户端。The NTP server sends to the client the time when the request message is received during the current time synchronization process, the reply message, and the time when the reply message is sent during the historical time synchronization process. 10.一种终端,其特征在于,所述终端包括存储器、处理器以及存储于所述存储器中并在所述处理器上运行的计算机程序,所述处理器用于执行程序数据以实现如权利要求1~9任一项所述的时间同步方法中的步骤。10. A terminal, characterized in that the terminal comprises a memory, a processor, and a computer program stored in the memory and running on the processor, wherein the processor is used to execute program data to implement the steps in the time synchronization method according to any one of claims 1 to 9. 11.一种计算机可读存储介质,其特征在于,所述计算机可读存储介质上存储有计算机程序,所述计算机程序被处理器执行时实现如权利要求1~9任一项所述的时间同步方法中的步骤。11. A computer-readable storage medium, characterized in that a computer program is stored on the computer-readable storage medium, and when the computer program is executed by a processor, the steps in the time synchronization method according to any one of claims 1 to 9 are implemented.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202411598005.9A CN119154985A (en) | 2024-11-11 | 2024-11-11 | Time synchronization method, terminal and computer readable storage medium |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202411598005.9A CN119154985A (en) | 2024-11-11 | 2024-11-11 | Time synchronization method, terminal and computer readable storage medium |
Publications (1)
Publication Number | Publication Date |
---|---|
CN119154985A true CN119154985A (en) | 2024-12-17 |
Family
ID=93812853
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202411598005.9A Pending CN119154985A (en) | 2024-11-11 | 2024-11-11 | Time synchronization method, terminal and computer readable storage medium |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN119154985A (en) |
Citations (5)
* Cited by examiner, † Cited by third partyPublication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US20070268938A1 (en) * | 2006-05-19 | 2007-11-22 | Dowd Gregory Louis | Network time protocol precision timestamping service |
CN104410481A (en) * | 2014-11-28 | 2015-03-11 | 国家电网公司 | Time synchronization method and time synchronization system based on NTP (network time protocol) network |
CN116488766A (en) * | 2023-05-11 | 2023-07-25 | 中国工商银行股份有限公司 | Clock synchronization state monitoring method and device, storage medium and electronic equipment |
CN116743303A (en) * | 2023-08-15 | 2023-09-12 | 北京智芯微电子科技有限公司 | Time synchronization method, device, computer equipment, chip and readable storage medium |
CN118694464A (en) * | 2024-08-23 | 2024-09-24 | 北京城建智控科技股份有限公司 | Time synchronization method, device and system |
-
2024
- 2024-11-11 CN CN202411598005.9A patent/CN119154985A/en active Pending
Patent Citations (5)
* Cited by examiner, † Cited by third partyPublication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US20070268938A1 (en) * | 2006-05-19 | 2007-11-22 | Dowd Gregory Louis | Network time protocol precision timestamping service |
CN104410481A (en) * | 2014-11-28 | 2015-03-11 | 国家电网公司 | Time synchronization method and time synchronization system based on NTP (network time protocol) network |
CN116488766A (en) * | 2023-05-11 | 2023-07-25 | 中国工商银行股份有限公司 | Clock synchronization state monitoring method and device, storage medium and electronic equipment |
CN116743303A (en) * | 2023-08-15 | 2023-09-12 | 北京智芯微电子科技有限公司 | Time synchronization method, device, computer equipment, chip and readable storage medium |
CN118694464A (en) * | 2024-08-23 | 2024-09-24 | 北京城建智控科技股份有限公司 | Time synchronization method, device and system |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN101960770B (en) | 2014-12-31 | Clock synchronization system, node, clock synchronization method |
US7865760B2 (en) | 2011-01-04 | Use of T4 timestamps to calculate clock offset and skew |
CN109392074B (en) | 2022-02-18 | Clock calibration method and device |
US7072432B2 (en) | 2006-07-04 | System and method for correcting the clock drift and maintaining the synchronization of low quality clocks in wireless networks |
US9167545B2 (en) | 2015-10-20 | Receiver, method of calculating time difference, and program |
US8416811B2 (en) | 2013-04-09 | Coordinated timing network having servers of different capabilities |
KR20150143801A (en) | 2015-12-23 | Timestamp generating method, device and system |
US12133185B2 (en) | 2024-10-29 | Synchronization method and device |
CN109981206A (en) | 2019-07-05 | Time synchronization method, device, system and terminal device, storage medium |
EP4010777A1 (en) | 2022-06-15 | Systems for timestamping events on edge devices |
WO2022257447A1 (en) | 2022-12-15 | Time synchronization method, network device, and storage medium |
US11272471B2 (en) | 2022-03-08 | Methods, apparatus and electronic devices for absolute time synchronization |
EP3598247B1 (en) | 2022-05-04 | Network time correction method and apparatus |
CN111478744B (en) | 2022-02-08 | Error adjusting method and system for time synchronization |
US7630383B2 (en) | 2009-12-08 | Synchronization of time stamps of peer devices in a communication node |
CN107749788A (en) | 2018-03-02 | A kind of method, apparatus and equipment for improving clock synchronization accuracy |
CN119154985A (en) | 2024-12-17 | Time synchronization method, terminal and computer readable storage medium |
CN102983959B (en) | 2015-05-13 | Method for realizing one-step mode and two-step mode for PTP (precision time synchronization protocol) in a plurality of MAC |
CN115529099A (en) | 2022-12-27 | Method, device, equipment and storage medium for timing calibration of vehicle domain controller |
CN113259039A (en) | 2021-08-13 | Time synchronization method and device, computer equipment and storage medium |
WO2020238997A1 (en) | 2020-12-03 | Time synchronization method, service board, and network device |
JP2001202156A (en) | 2001-07-27 | Time synchronizer |
CN116243586B (en) | 2024-09-03 | Vehicle time correction method and related equipment |
JP2002135284A (en) | 2002-05-10 | Line concentrator |
WO2024120469A1 (en) | 2024-06-13 | Clock synchronization method and apparatus, device, storage medium, and computer program |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
2024-12-17 | PB01 | Publication | |
2024-12-17 | PB01 | Publication | |
2025-01-03 | SE01 | Entry into force of request for substantive examination | |
2025-01-03 | SE01 | Entry into force of request for substantive examination |