Time synchronization method, terminal and computer readable storage medium

By calculating the difference between the response time of the NTP server and the reply message sending time as compensation time, the client clock is adjusted, which solves the problem of poor time synchronization accuracy in the prior art and achieves higher time synchronization accuracy.

CN119154985AInactive Publication Date: 2024-12-17ZHEJIANG DAHUA TECH CO LTD

Patent Information

Application Number
CN202411598005.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-11
Publication Date
2024-12-17
Estimated Expiration
Not applicable · inactive patent

AI Technical Summary

Technical Problem

In the prior art, the timing accuracy of the NTP time synchronization method is poor, mainly because the time of the reply message generated by the NTP server is inconsistent with the time of the reply message being sent, resulting in an increase in time delay and timing error.

Method used

By determining the difference between the response time and the reply message sending time as compensation time, the client clock is adjusted to improve the accuracy of time synchronization.

Benefits of technology

It improves the accuracy of NTP time synchronization of the client, solves the time delay problem caused by inconsistent reply message time and sending time, and enhances the accuracy of time synchronization.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119154985A_ABST
    Figure CN119154985A_ABST
Patent Text Reader

Abstract

The invention provides a time synchronization method, a terminal and a computer readable storage medium, the time synchronization method comprises a client and an NTP server, the client is in communication connection with the NTP server, and the method comprises the following steps: the client sends a generated request message to the NTP server; receiving a reply message which is made by the NTP server side based on the request message and contains response time and sending time of the NTP server side for sending the reply message; determining current compensation time based on the response time and the sending time; and adjusting the clock of the client based on the current compensation time. According to the method and the device, the problem of time delay caused by inconsistency of the response time in the reply message and the sending time of the reply message is considered, the current compensation time is determined through 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; and the time synchronization accuracy of the NTP of the client is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of network communication technology, and in particular to a time synchronization method, a terminal and a computer-readable storage medium. Background Art

[0002] There will be multiple devices working at the same time in the same local area network, and there is a continuous need for protocol interaction during the period, which requires that the time between the devices be consistent and accurate. Due to the different specifications of the device's own time crystal, the error gradually accumulates and increases over time, which requires time synchronization. At present, the NTP (Network Time Protocol) technology is mainly used to solve the clock synchronization problem of the current Internet; the Network Time Protocol (NTP) is a time synchronization service protocol, and its purpose is to provide a unified time synchronization service for devices running on the network. The existing conventional method for achieving network time synchronization is that the computer in the network sends and receives NTP protocol data packets with timestamps, and then calculates the current time difference based on the timestamp data carried by the NTP protocol data packets, and then takes the current system time to compensate for the current time difference, and then sets it to the system to synchronize its own time with the standard time. Summary of the invention

[0003] The main technical problem solved by the present invention is to provide a time synchronization method, a terminal and a computer-readable storage medium to solve the problem of poor time synchronization accuracy of NTP of the client in the prior art.

[0004] In order to solve the above technical problems, the first technical solution adopted by the present invention is: to provide a time synchronization method, including a client and an NTP server, wherein the communication connection between the client and the NTP server includes: The client sends the generated request message to the NTP server; Receive 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; Based on the response time and the sending time, determine the current compensation time; Adjust the client's clock based on the current compensation time.

[0005] The receiving end of the reply message containing the 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 include: Receive a reply message sent by the NTP server based on the request message in the current time synchronization process, including the response time and the time when the NTP server receives the request message; Receive the sending time of the reply message sent by the NTP server during the current time synchronization process; Based on the response time and the sending time, determine the current compensation time, including: 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.

[0006] The receiving end of the reply message containing the 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 include: Receive a reply message including a response time sent by the NTP server based on a request message in the current time synchronization process, the time when the NTP server receives the request message, and the time when the NTP server sends a historical reply message in the historical time synchronization process; Based on the response time and the sending time, determine the current compensation time, including: 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.

[0007] The receiving end includes a reply message containing a response time based on a request message in the current time synchronization process, a time when the NTP server receives the request message, and a sending time when the NTP server sends a historical reply message in the historical time synchronization process, including: Receive a reply message including a response time sent by the NTP server based on a request message in the current time synchronization process, the time when the NTP server receives the request message, and the time when the NTP server sends a historical reply message in the previous time synchronization process; 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, the current compensation time is determined, including: The current compensation time is determined based on the sending time of the historical reply message sent by the NTP server in the previous time synchronization process and the historical response time included in the historical reply message.

[0008] Among them, the sending time is no later than the response time, Based on the response time and the sending time, determine the current compensation time, including: Half of the difference between the sending time and the response time is determined as the current compensation time.

[0009] The client's clock is adjusted based on the current compensation time, including: 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.

[0010] In order to solve the above technical problems, the second technical solution adopted by the present invention is: to provide a time synchronization method, including a client and an NTP server, wherein the communication connection between the client and the NTP server includes: The NTP server receives the 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 adjusts the client's clock according to the current compensation time.

[0011] 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: The NTP server responds to the request message and uses the response time as a reply message; The NTP server sends the time of receiving the request message and the reply message to the client; After the reply message is sent, the NTP server sends the sending time of the reply message to the client.

[0012] 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: The NTP server responds to the request message in the current time synchronization process and uses the response time as the reply message; The NTP server sends 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 to the client.

[0013] To solve the above technical problems, the third technical solution adopted by the present invention is: to provide a terminal, the terminal includes a memory, a processor and a computer program stored in the memory and running on the processor, the processor is used to execute program data to implement the steps in the above-mentioned time synchronization method.

[0014] To solve the above technical problems, the fourth technical solution adopted by the present invention is: providing a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the steps in the above-mentioned time synchronization method are implemented.

[0015] The beneficial effects of the present invention are: different from the prior art, a time synchronization method, terminal and computer-readable storage medium are provided, the time synchronization method includes a client and an NTP server, and the communication connection between the client and the NTP server includes: the client sends a generated request message to the NTP server; receives a reply message containing a response time and the sending time of the reply message made by the NTP server based on the request message; determines the current compensation time based on the response time and the sending time; and adjusts the client's clock based on the current compensation time. In this application, the problem of time delay is caused by considering that the response time in the reply message is inconsistent with the sending time of the reply message, and then determines the current compensation time by the response time and the sending time of the reply message, and then compensates the client's clock according to the current compensation time, thereby improving the time synchronization accuracy of the client's NTP. BRIEF DESCRIPTION OF THE DRAWINGS

[0016] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.

[0017] Figure 1 It is a schematic diagram of information interaction of a time synchronization method provided in the prior art; Figure 2 It is a flowchart of the time synchronization method for a client provided by the present invention; Figure 3 It is a flow chart of the time synchronization method of the server provided by the present invention; Figure 4 This is a schematic diagram of information interaction in a specific embodiment of a time synchronization method provided by the present invention; Figure 5 is a schematic diagram of information interaction of another specific embodiment of the time synchronization method provided by the present invention; Figure 6 It is a schematic diagram of the framework of a terminal embodiment provided by the present invention; Figure 7 It is a schematic diagram of a framework of an embodiment of a computer-readable storage medium provided by the present invention. DETAILED DESCRIPTION

[0018] The scheme of the embodiment of the present application is described in detail below in conjunction with the drawings of the specification.

[0019] In the following description, for the purpose of explanation rather than limitation, specific details such as specific system structures, interfaces, and technologies are provided to facilitate a thorough understanding of the present application.

[0020] The term "and / or" in this article is only a description of the association relationship of the associated objects, indicating that there can be three relationships. For example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in this article generally indicates that the associated objects before and after are in an "or" relationship. In addition, "many" in this article means two or more than two.

[0021] 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 further described in detail below in conjunction with the accompanying drawings and specific implementation methods.

[0022] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art to which this application belongs. The terms used herein are only for the purpose of describing the embodiments of this application and are not intended to limit this application.

[0023] The time synchronization method provided in the embodiment of the present application can be implemented by the client or the server alone, or by the server and the terminal in collaboration. In some embodiments, the terminal or the server can implement the time synchronization method provided in the embodiment of the present application by running a computer program. For example, the computer program can be a native program or software module in the operating system; it can be a native application (APP, Application), that is, a program that needs to be installed in the operating system to run, such as a client that supports virtual scenes, such as a game APP; it can also be a small program, that is, a program that can be run only by downloading it to a browser environment; it can also be a small program that can be embedded in any APP. In short, the above-mentioned computer program can be an application, module or plug-in in any form.

[0024] See also Figure 1 , Figure 1 It is a schematic diagram of information interaction of a time synchronization method provided in the prior art.

[0025] The current NTP protocol process implements time synchronization between the client and the NTP server. The client sends an NTP request message to the NTP server, where the NTP request message contains the timestamp T1 when the message leaves the client. The NTP server receives the NTP request message, and the timestamp when the NTP server receives the NTP request message is T2. The NTP server processes the received NTP request message to obtain a reply message, where the reply message contains the processing time T3. The NTP server sends the reply message, the timestamp T2 when the NTP server receives the NTP request message, and the timestamp T1 when the NTP request message leaves the client to the client, and the timestamp when the client receives the reply message is T4.

[0026] The client calculates the delay time Delay of the NTP request message from the client to the NTP server and the time difference offset between the client and the NTP server based on the timestamp T1 when the NTP request message leaves the client, the timestamp T2 when the NTP server receives the NTP request message, the processing time T3 contained in the reply message, and the timestamp T4 when the client receives the reply message.

[0027] Specifically, the delay time Delay of the NTP request message from the client to the NTP server is calculated based on the following formula.

[0028] 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.

[0029] Offset = ((T2–T1) + (T3-T4)) / 2 (Formula 2) Specifically, the time Current Time after the client correction is calculated based on the following formula.

[0030] Current Time=T4+Offset=T3+Delay=(T4+T3+T2-T1) / 2 (Formula 3) The field of this proposal is the NTP time synchronization process of embedded devices. Traditional NTP timing is to mark the timestamp after the NTP message is parsed at the application layer. The software timestamp has a large error in accuracy due to the uncertainty of software execution. This problem is one of the main reasons for the increase in NTP timing errors. Specifically, the time of the reply message generated by the NTP server is inconsistent with the time when the NTP server sends the reply message. Specifically, the time when the NTP server sends the reply message is later than the time in the reply message, which increases the NTP timing error.

[0031] The time synchronization method provided in this embodiment takes into account that the time of the reply message generated by the NTP server is inconsistent with the time when the NTP server sends the reply message, and corrects the client time based on the difference between the time when the reply message is sent and the time when the reply message is generated.

[0032] The time synchronization method provided in this embodiment is suitable for a relatively stable local area network environment, and the time synchronization accuracy between the client and the NTP server is better through the time synchronization method provided in this embodiment.

[0033] See also Figure 2 , Figure 2It is a flow chart of the client time synchronization method provided by the present invention.

[0034] In this embodiment, a time synchronization method is provided, including a client and an NTP server, wherein the client and the NTP server are connected in communication. The execution subject of the time synchronization method in this embodiment is the client. The time synchronization method includes the following steps.

[0035] S11: The client sends the generated request message to the NTP server.

[0036] S12: 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.

[0037] S13: Determine the current compensation time based on the response time and the sending time.

[0038] S14: Adjust the client's clock based on the current compensation time.

[0039] In one embodiment, the client sends the generated request message to the NTP server, and the request message carries the timestamp of when the client sends the request message.

[0040] In one embodiment, the current compensation time is determined based on the response time and the sending time in the current time synchronization process.

[0041] Specifically, the specific implementation of receiving the reply message including the response time made by the NTP server based on the request message in step S12 and the sending time of the reply message sent by the NTP server is as follows.

[0042] Receive a reply message including a response time and the time when the NTP server receives the request message based on the request message during the current time synchronization process sent by the NTP server; receive the sending time of the reply message during the current time synchronization process sent by the NTP server.

[0043] Specifically, the specific implementation method of determining the current compensation time based on the response time and the sending time in step S13 is as follows.

[0044] 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.

[0045] Since the NTP server cannot send the sending time of the NTP server at the same time as sending the reply message, it is necessary to send the time of sending the reply message to the client later. This embodiment provides two methods for determining the current compensation time.

[0046] In one embodiment, the current compensation time is determined based on the response time and the sending time in the historical time synchronization process before the current time synchronization process.

[0047] Specifically, the specific implementation of receiving the reply message including the response time made by the NTP server based on the request message in step S12 and the sending time of the reply message sent by the NTP server is as follows.

[0048] Receive the reply message containing the 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 time when the NTP server sends the historical reply message in the historical time synchronization process.

[0049] In a specific embodiment, 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 the previous time synchronization process is received.

[0050] Specifically, the specific implementation method of determining the current compensation time based on the response time and the sending time in step S13 is as follows.

[0051] 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.

[0052] In a specific embodiment, in order to improve the accuracy of time synchronization, since the time synchronization method provided by this embodiment is suitable for a scenario where the local area network is stable, the clock of the client in the current time synchronization process can be adjusted based on the historical compensation time determined by the historical response time and the historical sending time in the historical time synchronization process closest to the current time synchronization process. Since 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 to improve the accuracy of the client's time synchronization.

[0053] The current compensation time is determined based on the sending time of the historical reply message sent by the NTP server in the previous time synchronization process and the historical response time included in the historical reply message.

[0054] Specifically, the specific implementation of adjusting the client clock based on the current compensation time in step S14 is as follows.

[0055] 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 reply message; the current compensation time is added to the initial time of the client to obtain the corrected time of the client.

[0056] The time synchronization method provided in this embodiment includes a client and an NTP server, and the communication connection between the client and the NTP server includes: the client sends a generated request message to the NTP server; receives a reply message containing a response time and the sending time of the reply message made by the NTP server based on the request message; determines the current compensation time based on the response time and the sending time; and adjusts the client's clock based on the current compensation time. In this application, the problem of time delay is caused by considering that the response time in the reply message is inconsistent with the sending time of the reply message, and then determines the current compensation time by the response time and the sending time of the reply message, and then compensates the client's clock according to the current compensation time, thereby improving the time synchronization accuracy of the client's NTP.

[0057] See also Figure 3 , Figure 3 It is a flow chart of the time synchronization method of the server provided by the present invention.

[0058] In this embodiment, a time synchronization method is provided, including a client and an NTP server, and the client and the NTP server are connected in communication. The execution subject of the time synchronization method in this embodiment is the NTP server. The time synchronization method includes the following steps.

[0059] S21: The NTP server receives the request message generated and sent by the client.

[0060] 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 adjusts the client's clock according to the current compensation time.

[0061] Specifically, in step 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 as shown in the following specific implementation.

[0062] In one embodiment, the NTP server responds to the request message and uses the response time as the reply message; the NTP server sends the time of receiving the request message and the reply message to the client; after the reply message is sent, the NTP server sends the sending time of the reply message to the client.

[0063] In another embodiment, the NTP server responds to the request message in the current time synchronization process and uses the response time as the reply message; the NTP server sends the time of receiving the request message in the current time synchronization process, the reply message, and the sending time of the reply message in the historical time synchronization process to the client.

[0064] In this application, the time delay problem caused by the inconsistency between the response time in the reply message and the sending time of the reply message is considered, and the current compensation time is determined by the response time and the sending time of the reply message, and then the client's clock is compensated according to the current compensation time, thereby improving the client's NTP time synchronization accuracy.

[0065] See also Figure 4 , Figure 4 It is a schematic diagram of information interaction of a specific embodiment of the time synchronization method provided by the present invention.

[0066] In a specific embodiment, in the time synchronization method, the current compensation time is determined based on the response time and the sending time in the current time synchronization process.

[0067] Specifically, the client sends the generated request message to the NTP server, and the request message carries the timestamp T1 of the client sending the request message; the NTP server receives the request message sent by the client, and the timestamp of the NTP server receiving the request message sent by the client is T2. The NTP server responds to the request message and generates a reply message containing the response time. Among them, 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 NTP server 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 of the client receiving 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 is T4. The NTP server continues to send an ACK message to the client carrying the timestamp T3´ of the NTP server sending the reply message to the client. The time when the NTP server sends the timestamp T3' to the client is T5. The time when the client receives the ACK message carrying the timestamp T3' of the reply message sent by the NTP server to the client is T6.

[0068] Specifically, the current compensation time ΔT is determined based on the response time and the sending time in the current time synchronization process.

[0069] ΔT = (T3´-T3) / 2 (Formula 4) Specifically, when the client receives the time T6' of the ACK message carrying the timestamp T3' when the NTP server sends the reply message to the client, the client's time is corrected based on the current compensation time ΔT in the current time synchronization process to obtain the current time T6'.

[0070] T6´=T6+ΔT (Formula 5) Through the above steps, the current time can be compensated when T6 is set to the system, so that the client time is consistent with the NTP server time, improving the accuracy of NTP time synchronization; and the increased ACK message resource overhead is small, and the impact on system performance and memory overhead are almost negligible; with the help of hardware timestamps, the timestamp accuracy of each time node is improved, solving the uncertainty of software timestamps during operation.

[0071] See also Figure 5 , Figure 5 It is a schematic diagram of information interaction of another specific embodiment of the time synchronization method provided by the present invention.

[0072] In a specific embodiment, in the time synchronization method, the current compensation time is determined based on the response time and the sending time in the historical time synchronization process before the current time synchronization process.

[0073] Specifically, in the current time synchronization process, the client sends the generated request message to the NTP server, and the request message carries the timestamp T of the client sending the request message. n+1 1; 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. The NTP server responds to the request message and generates a reply message containing the response time. The response time in the reply message is T n+1 3. The NTP server will reply to the message and the client send the request message with the timestamp T n+1 1 and the timestamp T when the NTP server receives the request message n+1 2 is sent to the client. The NTP server sends the reply message of the historical time synchronization process before the current time synchronization process to the client with the timestamp T n 3'. Timestamp T when the client receives the reply message and sends the request message n+1 1 and the timestamp T when the NTP server receives the request message n+1 2 is sent to the client. The NTP server sends the reply message of the historical time synchronization process before the current time synchronization process to the client with the timestamp T n 3' timestamp is T n+1 4.

[0074] Specifically, the current compensation time ΔT is determined based on the response time and the sending time in the historical time synchronization process before the current time synchronization process.

[0075] ΔT = (T n 3´-T n 3) / 2 (Formula 6) Specifically, the timestamp T when the client receives the reply message and sends the request message n+1 1 and the timestamp T when the NTP server receives the request message n+1 2 is sent to the client. The NTP server sends the reply message of the historical time synchronization process before the current time synchronization process to the client with the timestamp T n 3' time T n+1 At 4 o'clock, based on the current compensation time ΔT corresponding to the historical time synchronization process before the current time synchronization process, the client's time is corrected to obtain the current time T n+1 4´.

[0076] T n+1 4´=(T n+1 3+T n+1 4-T n+1 1+T n+1 2) / 2+ΔT (Formula 7) In this embodiment, during the n+1 time synchronization process, the compensation time during the n time synchronization process is carried in the reply message, and the clock of the client during the n+1 time synchronization process is compensated based on the compensation time during the n time synchronization process, thereby improving the accuracy of NTP time synchronization. First, complete the traditional NTP interaction to set the synchronization time to the system, and then perform the error compensation action to avoid the situation where the time cannot be calibrated due to a failure in the error calculation process; obtain more accurate timestamp information without modifying the NTP message interaction process, greatly improving the accuracy of NTP.

[0077] See also Figure 6 , Figure 6 80 is a schematic diagram of a terminal embodiment provided by the present invention. The terminal 80 includes a memory 81 and a processor 82 coupled to each other, and the processor 82 is used to execute program instructions stored in the memory 81 to implement the steps of any of the above-mentioned time synchronization method embodiments. In a specific implementation scenario, the terminal 80 may include but is not limited to: a microcomputer, a server, and in addition, the terminal 80 may also include a mobile device such as a laptop computer and a tablet computer, which is not limited here.

[0078] Specifically, the processor 82 is used to control itself and the memory 81 to implement the steps of any of the above-mentioned time synchronization method embodiments. The processor 82 can also be called a CPU (Central Processing Unit). The processor 82 may be an integrated circuit chip with signal processing capabilities. The processor 82 can also be a general-purpose processor, a digital signal processor (Digital Signal Processor, DSP), an application-specific integrated circuit (Application Specific Integrated Circuit, ASIC), a field-programmable gate array (Field-Programmable Gate Array, FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor, etc. In addition, the processor 82 can be implemented by an integrated circuit chip.

[0079] The above scheme, a time synchronization method, includes a client and an NTP server, and the communication connection between the client and the NTP server includes: The client sends the generated request message to the NTP server; Receive 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; Based on the response time and the sending time, determine the current compensation time; Adjust the client's clock based on the current compensation time.

[0080] Alternatively, a time synchronization method includes a client and an NTP server, wherein the communication connection between the client and the NTP server includes: The NTP server receives the 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 adjusts the client's clock according to the current compensation time.

[0081] See also Figure 7 , Figure 7 The computer-readable storage medium 90 stores program instructions 901 that can be executed by a processor, and the program instructions 901 are used to implement the steps of any of the above-mentioned time synchronization method embodiments.

[0082] The above scheme, a time synchronization method, includes a client and an NTP server, and the communication connection between the client and the NTP server includes: The client sends the generated request message to the NTP server; Receive 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; Based on the response time and the sending time, determine the current compensation time; Adjust the client's clock based on the current compensation time.

[0083] Alternatively, a time synchronization method includes a client and an NTP server, wherein the communication connection between the client and the NTP server includes: The NTP server receives the 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 adjusts the client's clock according to the current compensation time.

[0084] In some embodiments, the functions or modules included in the device provided by the embodiments of the present disclosure can be used to execute the method described in the above method embodiments. The specific implementation can refer to the description of the above method embodiments, and for the sake of brevity, it will not be repeated here.

[0085] The above description of various embodiments tends to emphasize the differences between the various embodiments. The same or similar aspects can be referenced to each other, and for the sake of brevity, they will not be repeated herein.

[0086] In the several embodiments provided in the present application, it should be understood that the disclosed methods and devices can be implemented in other ways. For example, the device implementation described above is only schematic. For example, the division of modules or units is only a logical function division. There may be other division methods in actual implementation, such as units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, and the indirect coupling or communication connection of devices or units can be electrical, mechanical or other forms.

[0087] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.

[0088] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product. The computer software product is stored in a storage medium, including several instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) or a processor to execute all or part of the steps of each implementation method of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk and other media that can store program code.

[0089] The above are only implementation modes of the present invention, and are not intended to limit the patent protection scope of the present invention. Any equivalent structure or equivalent process transformation made using the contents of the present invention specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present invention.

Claims

1. A time synchronization method, characterized in that: The client and the NTP server are connected in communication, including: The client sends the generated request message to the NTP server; 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. The time synchronization method according to claim 1, characterized in that: 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: 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; 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. The time synchronization method according to claim 1, characterized in that: 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: 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: 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. The time synchronization method according to claim 3, characterized in that: 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: 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; 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: 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. The time synchronization method according to claim 1, characterized in that: 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. 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: 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. A time synchronization method, characterized in that: The client and the NTP server are connected in communication, including: The NTP server receives the 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 adjusts the client's clock according to the current compensation time.

8. The time synchronization method according to claim 7, characterized in that: 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: The NTP server responds to the request message and uses the response time as the reply message; The NTP server sends the time of receiving the request message and the reply message to the client; After the reply message is sent, the NTP server sends the sending time of the reply message to the client.

9. The time synchronization method according to claim 7, characterized in that: 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: The NTP server responds to the request message in the current time synchronization process and uses the response time as the reply message; 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. A terminal, characterized in that: The terminal includes a memory, a processor, and a computer program stored in the memory and running on the processor, and 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. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, 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.

Citation Information

Patent Citations

  • Time synchronization method and time synchronization system based on NTP (network time protocol) network

    CN104410481A

  • Clock synchronization state monitoring method and device, storage medium and electronic equipment

    CN116488766A

  • Time synchronization method and device, computer equipment, chip and readable storage medium

    CN116743303A

  • Time synchronization method, device and system

    CN118694464A

  • Network time protocol precision timestamping service

    US20070268938A1

Cited By

  • Time synchronization method and apparatus, electronic device, storage medium, and program product

    WO2026149415A1