Time synchronization method and device, electronic equipment and storage medium
The client sends time synchronization requests to obtain the time difference on the server, and combines the time difference on the historical synchronization requests to synchronize the client, solving the problems of complex and large deviations in the existing technology, and achieving more stable and accurate time synchronization.
Patent Information
- Application Number
- CN202411750745.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-29
- Publication Date
- 2025-03-11
AI Technical Summary
In the prior art, the local area network time synchronization methods such as NTP and PTP are complicated, and there is a problem that there is no response when the request is too fast or the reply time value is 0, resulting in a large deviation when the client directly uses server time for synchronization.
The client sends the first time synchronization request and the second historical time synchronization request to the server, receives corresponding time information, determines the first time difference and the second time difference between the client and the server, and performs time synchronization of the client according to these two time differences.
Improve the stability and accuracy of time synchronization, reduce time deviation, avoid time jumps, and ensure the consistency between the client and server time.
Smart Images

Figure CN119602903A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of data processing technology, specifically to the field of communication transmission and time synchronization, and in particular to a time synchronization method, device, electronic device and storage medium. Background Art
[0002] LAN time synchronization usually uses the Network Time Protocol (NTP) or Precision Time Protocol (PTP) synchronization methods. The processing of the two is relatively complicated, and there will be problems such as no response when the request is too fast, or the reply time value is 0; therefore, time synchronization can be performed by requesting interaction between the client and the server, but the deviation is large when the client directly uses the server time for synchronization. Summary of the invention
[0003] The present disclosure provides a time synchronization method, device, electronic device and storage medium.
[0004] According to one aspect of the present disclosure, a time synchronization method is provided, which is performed by a client, and the method includes:
[0005] Sending a first time synchronization request to a server, and receiving time information corresponding to the first time synchronization request sent by the server;
[0006] Determine a first time difference between the client and the server according to the time information;
[0007] Obtaining a second time difference corresponding to a historical second time synchronization request, where the second time synchronization request is a request sent in a previous synchronization cycle;
[0008] The client is time synchronized according to the first time difference and the second time difference.
[0009] According to another aspect of the present disclosure, a time synchronization method is provided, which is performed by a server, and the method includes:
[0010] receiving a first time synchronization request and a historical second time synchronization request sent by a client, wherein the first time synchronization request and the second time synchronization request are requests sent in different synchronization cycles, and the different synchronization cycles are adjacent;
[0011] Sending time information corresponding to the first time synchronization request and time information corresponding to the second time synchronization request to the client;
[0012] The time information corresponding to the first time synchronization request is used to determine a first time difference between the client and the server, and the time information corresponding to the second time synchronization request is used to determine a second time difference between the client and the server. The first time difference and the second time difference are used to perform time synchronization on the client.
[0013] According to a third aspect of the present disclosure, a time synchronization device is provided, which is executed by a client, and the device includes:
[0014] A transceiver module, used to send a first time synchronization request to a server, and receive time information corresponding to the first time synchronization request sent by the server;
[0015] A first acquisition module, used to determine a first time difference between the client and the server according to the time information;
[0016] A second acquisition module, used to acquire a second time difference corresponding to a historical second time synchronization request, where the second time synchronization request is a request sent in a previous synchronization cycle;
[0017] A time synchronization module is used to perform time synchronization on the client according to the first time difference and the second time difference.
[0018] According to a fourth aspect of the present disclosure, another time synchronization device is provided, which is executed by a server, and the device includes:
[0019] A receiving module, configured to receive a first time synchronization request and a historical second time synchronization request sent by a client, wherein the first time synchronization request and the second time synchronization request are requests sent in different synchronization cycles, and the different synchronization cycles are adjacent;
[0020] A sending module, configured to send time information corresponding to the first time synchronization request and time information corresponding to the second time synchronization request to the client;
[0021] The time information corresponding to the first time synchronization request is used to determine a first time difference between the client and the server, and the time information corresponding to the second time synchronization request is used to determine a second time difference between the client and the server. The first time difference and the second time difference are used to perform time synchronization on the client.
[0022] According to a fifth aspect of the present disclosure, an electronic device is provided, comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the method described in any one of the first aspect or the second aspect embodiments.
[0023] According to a sixth aspect of the present disclosure, a non-transitory computer-readable storage medium storing computer instructions is provided, wherein the computer instructions are used to enable the computer to execute the method described in any one of the first aspect or the second aspect embodiments.
[0024] According to a seventh aspect of the present disclosure, a computer program product is provided, comprising a computer program, wherein when the computer program is executed by a processor, the steps of the method described in any one of the embodiments of the first aspect or the second aspect are implemented.
[0025] It should be understood that the content described in this section is not intended to identify the key or important features of the embodiments of the present disclosure, nor is it intended to limit the scope of the present disclosure. Other features of the present disclosure will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0026] The accompanying drawings are used to better understand the present solution and do not constitute a limitation of the present disclosure.
[0027] Figure 1 is a flowchart of a time synchronization method provided by an embodiment of the present disclosure;
[0028] Figure 2 is a flowchart of a time synchronization method provided by an embodiment of the present disclosure;
[0029] Figure 3 is a flowchart of a time synchronization method provided by an embodiment of the present disclosure;
[0030] Figure 4 is a flowchart of a time synchronization method provided by an embodiment of the present disclosure;
[0031] Figure 5 is an interactive schematic diagram of a time synchronization method provided by an embodiment of the present disclosure;
[0032] Figure 6 is a structural block diagram of a time synchronization device provided by an embodiment of the present disclosure;
[0033] Figure 7 is a structural block diagram of another time synchronization device provided by an embodiment of the present disclosure;
[0034] Figure 8 is a schematic block diagram of an example electronic device for implementing an embodiment of the present disclosure. DETAILED DESCRIPTION
[0035] The following is a description of exemplary embodiments of the present disclosure in conjunction with the accompanying drawings, including various details of the embodiments of the present disclosure to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present disclosure. Similarly, for the sake of clarity and conciseness, descriptions of well-known functions and structures are omitted in the following description.
[0036] Data processing is the collection, storage, retrieval, processing, transformation and transmission of data. Its basic purpose is to extract and derive valuable and meaningful data for certain specific people from a large amount of data that may be disorganized and difficult to understand.
[0037] Communication transmission refers to the transmission and exchange of information from one place to another. Its purpose is to transmit messages. It focuses on the transmission method, efficiency and security of information in the communication network. Communication transmission methods can be divided into wired communication (such as cables or optical cables) and wireless communication (such as electromagnetic waves), etc., which realize long-distance transmission of information through different transmission media and signal forms.
[0038] Time synchronization refers to making the clocks of different devices or components reach a unified time standard in a network or system to ensure the time consistency between them. It can include frequency synchronization, phase synchronization and time synchronization. Frequency synchronization means that different signals have the same number of pulses in the same time interval. Phase synchronization means that two signals have the same frequency and the start and end time of each pulse are the same. Time synchronization means that two signals not only have the same frequency and phase, but also the order in which the pulses appear is the same.
[0039] Figure 1 is a flow chart of a time synchronization method provided by an embodiment of the present disclosure; Figure 1 As shown, the method is executed by the client and includes:
[0040] S101, sending a first time synchronization request to a server, and receiving time information corresponding to the first time synchronization request sent by the server.
[0041] In some implementations, the client may be a computer, mobile device, browser, or other application, and may send a request to the server. For example, in this embodiment, the client sends a first time synchronization request to the server to request time information in the server.
[0042] In some implementations, the service end may be a computer or server that provides services and is capable of receiving requests from the client and providing corresponding services or resources based on the requests. By way of example, this embodiment may be applicable to the time synchronization of a host and a slave in an autonomous driving vehicle control system.
[0043] After receiving the first time synchronization request, the server generates a corresponding response message according to the first time synchronization request, and the response message includes at least the time information requested by the client. The client receives the response message to obtain the time information corresponding to the first time request.
[0044] Optionally, the time information may include one or more of the current time of the server, the time when the server receives the first time synchronization request, and the time when the client sends a response message.
[0045] S102: Determine a first time difference between the client and the server according to the time information.
[0046] The client determines the time data of the server according to the time information, and calculates the difference between the time data of the server and the time data of the client itself to obtain a first time difference between the client and the server.
[0047] S103: Obtain a second time difference corresponding to a historical second time synchronization request.
[0048] The second time synchronization request is a request sent in the previous synchronization cycle. The second time difference is the time difference between the client and the server corresponding to the request sent in the previous synchronization cycle. Each synchronization cycle can be a fixed time interval, which is not described in detail in this embodiment.
[0049] S104: Perform time synchronization on the client according to the first time difference and the second time difference.
[0050] It is understandable that when the time of the server and the client both change stably, the results of the first time difference and the second time difference are similar, so it can be determined whether to perform time synchronization based on the results of the first time difference and the second time difference.
[0051] For example, assuming that the first time difference is significantly different from the second time difference, it means that the time provided by the server is not stable enough and the time difference is large, then the time requested this time is inaccurate data and time synchronization is not performed; on the contrary, when the first time difference is slightly different from the second time difference, it means that the time provided by the server is stable and the time difference is small, then the client time can be synchronized according to the data from the server requested this time, that is, the client time is updated to the time returned by the server to achieve the purpose of time synchronization.
[0052] In this embodiment, the client sends a first time synchronization request to the server, and receives time information of the server's response to the first time synchronization request, and determines the first time difference between the client and the server for this request based on the time information; obtains the second time difference corresponding to the historical second synchronization request, and performs time synchronization when the first time difference and the second time difference are the same or similar, thereby improving the stability and accuracy of time synchronization and avoiding time jumps.
[0053] Figure 2 is a flow chart of a time synchronization method provided by an embodiment of the present disclosure; Figure 2 As shown, the method is executed by the client and includes:
[0054] S201, sending a first time synchronization request to a server, and receiving time information corresponding to the first time synchronization request sent by the server.
[0055] In some implementations, a frame header and checksum information of a first time synchronization request are generated for a first time synchronization request; wherein the frame headers and checksum information of different time synchronization requests are different and are used to uniquely represent the corresponding time synchronization request. Based on the frame header and checksum information, a first time synchronization request is generated and sent to a server. That is, the frame header and checksum information are carried in the first time synchronization request, and verification is performed based on the frame header and checksum information. The server sends the time after the verification is successful to ensure data security.
[0056] In some implementations, the time synchronization request can be retransmitted according to the set retransmission configuration information until the time information corresponding to the time synchronization request is obtained. The retransmission configuration information includes at least one parameter of the number of retransmissions and the time interval between two adjacent transmissions to avoid omissions or failures in sending the time synchronization request, and ensure that the server can normally receive the first time synchronization request.
[0057] For example, the number of retransmissions is 3, the time interval is 100ms, and the client sends a first time request to the server. If the time information of the server is not received after an interval of 100ms, the client sends the first time synchronization request again until the time information corresponding to the time synchronization request is obtained, or the client stops sending the time synchronization request when the number of retransmissions is reached.
[0058] In the embodiments of the present disclosure, the implementation method of step S201 can be implemented by any of the methods in the embodiments of the present disclosure, which is not limited here and will not be described in detail.
[0059] S202: Determine a first time difference between the client and the server according to the time information.
[0060] Optionally, the first time of the client corresponding to the first time synchronization request can be obtained; the second time fed back by the server can be determined based on the time information; the time offset between the first time and the second time can be obtained as the first time difference; that is, the time deviation between the first time of the client and the second time fed back by the server is calculated, and the time deviation is used as the first time difference to intuitively determine the time difference between the client and the server.
[0061] In the embodiments of the present disclosure, the implementation method of step S202 may be implemented in any manner in the embodiments of the present disclosure, which is not limited here and will not be described in detail.
[0062] S203: Obtain a second time difference corresponding to a historical second time synchronization request.
[0063] Optionally, the first time of the client corresponding to the second time synchronization request can be obtained; the second time fed back by the server can be determined based on the time information; the time offset between the first time and the second time can be obtained as the second time difference; that is, the time deviation between the first time of the client and the second time fed back by the server when the second time synchronization request is obtained, and the time deviation is used as the second time difference.
[0064] In the embodiments of the present disclosure, the implementation method of step S203 may be implemented in any manner in the embodiments of the present disclosure, which is not limited here and will not be described in detail.
[0065] S204: Obtain a third time difference between the first time difference and the second time difference.
[0066] For example, the first time difference is expressed as diff_c, the second time difference is expressed as diff_L, and the third time difference diff=fabs(diff_c-diff_L), wherein fabs is an absolute value calculation.
[0067] S205: Perform time synchronization on the client according to the third time difference.
[0068] Optionally, a first set time value may be set for time difference comparison, and in response to the third time difference being less than the first set time value, indicating that the first time difference is relatively close to the second time difference, and the value of the third time difference is relatively small, time synchronization is performed on the client based on the time information corresponding to the first time synchronization request of the server, so as to ensure the stability of time synchronization;
[0069] In response to the third time difference being greater than or equal to the first set time value, indicating that the first time difference is significantly different from the second time difference and the time change on the server is significantly, a third time synchronization request is resent to the server, that is, a time synchronization request is sent to the server again to re-acquire time information that meets the conditions to perform time synchronization on the client and ensure the stability of time synchronization.
[0070] In this embodiment, when the client sends a first time synchronization request to the server, the frame header and checksum information of the first time synchronization request are sent at the same time. After the server successfully verifies the frame header and checksum information, the time information is sent to ensure data security. The time synchronization request can also be retransmitted based on the set retransmission configuration information to avoid accidental omissions or failures when sending the request. After receiving the time information, the second time of the server is determined according to the time information, and the first time difference is determined according to the second time of the server and the first time of the client. Similarly, the second time difference of the previous time synchronization request is obtained, and the deviation between the first time difference and the second time difference is calculated as the third time difference. Based on whether the third time difference is less than the first set time value, it is determined whether to perform time synchronization on the client to ensure the stability of time synchronization.
[0071] Figure 3 is a flow chart of a time synchronization method provided by an embodiment of the present disclosure; Figure 3 As shown, the method is executed by the client and includes:
[0072] S301, sending a first time synchronization request to a server, and receiving time information corresponding to the first time synchronization request sent by the server.
[0073] In the embodiments of the present disclosure, the implementation method of step S301 may be implemented in any manner in the embodiments of the present disclosure, which is not limited here and will not be described in detail.
[0074] S302: Determine a first time difference between the client and the server according to the time information.
[0075] In the embodiments of the present disclosure, the implementation method of step S302 may be implemented in any manner in the embodiments of the present disclosure, which is not limited here and will not be described in detail.
[0076] S303: Obtain a second time difference corresponding to a historical second time synchronization request.
[0077] In the embodiments of the present disclosure, the implementation method of step S303 may be implemented in any manner in the embodiments of the present disclosure, which is not limited here and will not be described in detail.
[0078] S304: Obtain a third time difference between the first time difference and the second time difference.
[0079] In the embodiments of the present disclosure, the implementation method of step S304 may be implemented in any manner in the embodiments of the present disclosure, which is not limited here and will not be described in detail.
[0080] S305: Perform time synchronization on the client according to the third time difference.
[0081] In the embodiments of the present disclosure, the implementation method of step S305 can be implemented by any of the methods in the embodiments of the present disclosure, which is not limited here and will not be described in detail.
[0082] S306: Determine a round trip delay of the first time synchronization request according to the time information.
[0083] Optionally, the receiving time of the time information can be obtained; the sending time of the first time synchronization request can be obtained; and the round-trip delay can be determined based on the receiving time and the sending time, that is, the time interval between the sending time of the first time synchronization request and the receiving time of the received time information, which is the round-trip delay of the first time synchronization request. The round-trip delay reflects the time delay in communication between the client and the server, and avoids erroneous time synchronization caused by excessive time delay.
[0084] S307: Identify abnormalities in the time information based on the round-trip delay.
[0085] It is understandable that the smaller the round-trip delay is, the closer the time when the server time information is received is to the second time sent by the server, and the more reliable the time data in the time information is; therefore, it is possible to determine whether there is an abnormality in the time information based on the round-trip delay.
[0086] In some implementations, in response to a round-trip delay being greater than a second set time value, it is determined that the time information is in an abnormal state; in response to a round-trip delay being less than or equal to the second set time value, it is determined that the time information is in a normal state, that is, when the round-trip delay is longer, the network delay is larger, and the time information is in an abnormal state; when the round-trip delay is shorter, the network delay is smaller, and the time information is determined to be in a normal state, thereby avoiding synchronization of the client based on abnormal time.
[0087] In some implementations, in response to the time information being in an abnormal state, the time information is discarded, and a third time synchronization request is resent to the server to reacquire the time information in a normal state to ensure the accuracy and stability of the time synchronization.
[0088] In this embodiment, after obtaining the third time difference and preliminarily determining that time synchronization can be performed based on the third time difference, the sending time of the first time synchronization request sent by the client and the receiving time of the time information corresponding to the first time synchronization request are determined, and the round-trip delay is determined based on the sending time and the receiving time, so as to determine whether there is a network delay at present through the round-trip delay, thereby identifying anomalies based on the round-trip delay, avoiding the client from synchronizing with the wrong time, improving the stability and accuracy of time synchronization, and avoiding time synchronization errors caused by time jumps.
[0089] Figure 4 is a flow chart of a time synchronization method provided by an embodiment of the present disclosure; Figure 4 As shown, the method is executed by the server and includes:
[0090] S401, receiving a first time synchronization request sent by a client and a historical second time synchronization request.
[0091] The first time synchronization request and the second time synchronization request are requests sent in different synchronization cycles, and the different synchronization cycles are adjacent; the first time synchronization request and the second time synchronization request are both used to request time information.
[0092] Optionally, a frame header and checksum information may be obtained from each time synchronization request; the client may be verified based on the frame header and checksum information; after verification, time information corresponding to the time synchronization request may be sent to the client, and a security check may be performed before time synchronization to improve interaction security.
[0093] S402: Send time information corresponding to the first time synchronization request and time information corresponding to the second time synchronization request to the client.
[0094] The time information corresponding to the first time synchronization request is used to determine the first time difference between the client and the server, and the time information corresponding to the second time synchronization request is used to determine the second time difference between the client and the server. The first time difference and the second time difference are used to synchronize the client.
[0095] In this embodiment, after receiving the first time synchronization request and the second time synchronization request sent by the client, verification is performed based on the frame header and checksum information. After the verification is successful, the time information is sent to the client to ensure the security of the time data, so that the client can perform time synchronization processing according to the time information corresponding to the time synchronization request, thereby improving the security and accuracy of time synchronization.
[0096] Figure 5 is an interactive schematic diagram of a time synchronization method provided by an embodiment of the present disclosure; Figure 5 As shown, the method includes:
[0097] S501, the client sends a first time synchronization request to the server.
[0098] S502: The server receives a first time synchronization request sent by the client, and sends time information corresponding to the first time synchronization request to the client.
[0099] S503: The client determines a first time difference between the client and the server according to the time information.
[0100] S504: The client sends a second time synchronization request to the server.
[0101] S505: The server receives the second time synchronization request sent by the client, and sends time information corresponding to the second time synchronization request to the client.
[0102] S506: The client obtains a second time difference corresponding to a historical second time synchronization request according to the time information.
[0103] S507: The client obtains a third time difference between the first time difference and the second time difference.
[0104] S508: The client performs time synchronization on the client according to the third time difference.
[0105] S509: The client determines a round-trip delay of the first time synchronization request according to the time information.
[0106] S510: The client identifies anomalies in the time information based on the round-trip delay.
[0107] In the embodiments of the present disclosure, the implementation method of steps S501-S510 can be implemented in any manner in the embodiments of the present disclosure, which is not limited here and will not be described in detail.
[0108] In this embodiment, time information is acquired through interaction between the client and the server. After the client receives the time information corresponding to the first time synchronization request and the second time synchronization request, the first time difference and the second time difference are determined according to the time information, and the deviation between the first time difference and the second time difference is calculated as the third time difference. According to whether the third time difference is less than the first set time value, it is determined whether to synchronize the client to ensure the stability of the time synchronization, and the round-trip delay between the client sending and receiving the time information is further determined to determine whether there is a network delay at present through the round-trip delay, so as to identify anomalies according to the round-trip delay, avoid the client synchronizing the wrong time, improve the stability and accuracy of the time synchronization, and avoid the time jump causing the time synchronization error.
[0109] Figure 6is a structural block diagram of a time synchronization device provided by an embodiment of the present disclosure; Figure 6 As shown, executed by the client, the time synchronization device 600 includes:
[0110] The transceiver module 601 is used to send a first time synchronization request to the server, and receive time information corresponding to the first time synchronization request sent by the server;
[0111] A first acquisition module 602, configured to determine a first time difference between the client and the server according to the time information;
[0112] A second acquisition module 603 is used to acquire a second time difference corresponding to a historical second time synchronization request, where the second time synchronization request is a request sent in a previous synchronization cycle;
[0113] The time synchronization module 604 is used to perform time synchronization on the client according to the first time difference and the second time difference.
[0114] In some implementations, the apparatus 600 further includes:
[0115] For any time difference between the first time difference and the second time difference, obtaining a first time of a client corresponding to a time synchronization request associated with any time difference;
[0116] Determine the second time fed back by the server according to the time information corresponding to any time difference;
[0117] Gets the time offset between the first time and the second time as any time difference.
[0118] In some implementations, the time synchronization module 604 includes:
[0119] Obtain a third time difference between the first time difference and the second time difference;
[0120] In response to the third time difference being less than the first set time value, performing time synchronization on the client based on the time information corresponding to the first time synchronization request;
[0121] In response to the third time difference being greater than or equal to the first set time value, a third time synchronization request is re-sent to the server to re-acquire time information that meets the conditions to perform time synchronization on the client.
[0122] In some implementations, the apparatus 600 further includes:
[0123] Determine a round trip delay of a first time synchronization request according to the time information;
[0124] According to the round-trip delay, the time information is anomaly identified;
[0125] In response to the time information being in an abnormal state, the time information is discarded, and a third time synchronization request is resent to the server to reacquire the time information in a normal state.
[0126] In some implementations, the apparatus 600 includes:
[0127] In response to the round-trip delay being greater than a second set time value, determining that the time information is in an abnormal state;
[0128] In response to the round trip delay being less than or equal to the second set time value, it is determined that the time information is in a normal state.
[0129] In some implementations, the apparatus 600 includes:
[0130] Get the receiving moment of time information;
[0131] Get the sending time of the first time synchronization request;
[0132] The round-trip delay is determined based on the receiving time and the sending time.
[0133] In some implementations, the apparatus 600 further includes:
[0134] The time synchronization request is retransmitted according to the set retransmission configuration information until the time information corresponding to the time synchronization request is obtained.
[0135] In some implementations, the retransmission configuration information includes at least one parameter of the number of retransmissions and a time interval between two adjacent transmissions.
[0136] In some implementations, the apparatus 600 further includes:
[0137] For each time synchronization request, generate a frame header and checksum information of the time synchronization request;
[0138] Based on the frame header and checksum information, a time synchronization request is generated and sent to the server.
[0139] In this embodiment, when the client sends a first time synchronization request to the server, the frame header and checksum information of the first time synchronization request are sent at the same time for verification to ensure data security. The time synchronization request can also be retransmitted based on the set retransmission configuration information to avoid accidental omissions or failures when sending the request. After receiving the time information, the first time difference and the second time difference are determined according to the time information, and the deviation between the first time difference and the second time difference is calculated as the third time difference. According to whether the third time difference is less than the first set time value, it is determined whether to synchronize the client to ensure the stability of the time synchronization, and the round-trip delay between the client sending and receiving the time information is further determined to determine whether there is a network delay at present through the round-trip delay, so as to identify anomalies based on the round-trip delay, avoid the client synchronizing with the wrong time, improve the stability and accuracy of the time synchronization, and avoid the situation where the time jump causes the time synchronization error.
[0140] Figure 7 is a structural block diagram of another time synchronization device provided by an embodiment of the present disclosure; Figure 7 As shown, the time synchronization device 700 is executed by the server and includes:
[0141] A receiving module 701 is configured to receive a first time synchronization request and a historical second time synchronization request sent by a client, wherein the first time synchronization request and the second time synchronization request are requests sent in different synchronization cycles, and the different synchronization cycles are adjacent;
[0142] A sending module 702, configured to send time information corresponding to the first time synchronization request and time information corresponding to the second time synchronization request to the client;
[0143] The time information corresponding to the first time synchronization request is used to determine the first time difference between the client and the server, and the time information corresponding to the second time synchronization request is used to determine the second time difference between the client and the server. The first time difference and the second time difference are used to synchronize the client.
[0144] In some implementations, the apparatus 700 further includes:
[0145] Get the frame header and checksum information from each time synchronization request;
[0146] Verify the client based on the frame header and checksum information;
[0147] After verification, the time information corresponding to the time synchronization request is sent to the client.
[0148] In this embodiment, after receiving the first time synchronization request and the second time synchronization request sent by the client, verification is performed based on the frame header and checksum information. After the verification is successful, the time information is sent to the client to ensure the security of the time data, so that the client can perform time synchronization processing according to the time information corresponding to the time synchronization request, thereby improving the security and accuracy of time synchronization.
[0149] In the technical solution disclosed herein, the acquisition, storage and application of user personal information involved are in compliance with the provisions of relevant laws and regulations and do not violate public order and good morals.
[0150] According to an embodiment of the present disclosure, the present disclosure also provides an electronic device, a readable storage medium and a computer program product.
[0151] Figure 8 is a schematic block diagram of an example electronic device used to implement an embodiment of the present disclosure. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device may also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present disclosure described and / or claimed herein.
[0152] like Figure 8 As shown, the device 800 includes a computing unit 801, which can perform various appropriate actions and processes according to a computer program stored in a read-only memory (ROM) 802 or a computer program loaded from a storage unit 808 into a random access memory (RAM) 803. In the RAM 803, various programs and data required for the operation of the device 800 can also be stored. The computing unit 801, the ROM 802, and the RAM 803 are connected to each other via a bus 804. An input / output (I / O) interface 805 is also connected to the bus 804.
[0153] A number of components in the device 800 are connected to the I / O interface 805, including: an input unit 806, such as a keyboard, a mouse, etc.; an output unit 807, such as various types of displays, speakers, etc.; a storage unit 808, such as a disk, an optical disk, etc.; and a communication unit 809, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 809 allows the device 800 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.
[0154] The computing unit 801 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the computing unit 801 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, digital signal processors (DSPs), and any appropriate processors, controllers, microcontrollers, etc. The computing unit 801 performs the various methods and processes described above, such as a time synchronization method. For example, in some embodiments, the time synchronization method may be implemented as a computer software program, which is tangibly contained in a machine-readable medium, such as a storage unit 808. In some embodiments, part or all of the computer program may be loaded and / or installed on the device 800 via ROM 802 and / or communication unit 809. When the computer program is loaded into RAM 803 and executed by the computing unit 801, one or more steps of the time synchronization method described above may be performed. Alternatively, in other embodiments, the computing unit 801 may be configured to perform the time synchronization method in any other appropriate manner (e.g., by means of firmware).
[0155] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), load programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0156] The program code for implementing the method of the present disclosure may be written in any combination of one or more programming languages. These program codes may be provided to a processor or controller of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that the program code, when executed by the processor or controller, enables the functions / operations specified in the flow chart and / or block diagram to be implemented. The program code may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.
[0157] In the context of the present disclosure, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or equipment, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0158] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user can provide input to the computer. Other types of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic input, voice input, or tactile input).
[0159] The systems and techniques described herein may be implemented in a computing system that includes back-end components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes front-end components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such back-end components, middleware components, or front-end components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), and the Internet.
[0160] A computer system may include a client and a server. The client and the server are generally remote from each other and usually interact through a communication network. The relationship of client and server is generated by computer programs running on respective computers and having a client-server relationship with each other. The server may be a cloud server, a server of a distributed system, or a server combined with a blockchain.
[0161] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps recorded in this disclosure can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solutions disclosed in this disclosure can be achieved, and this document does not limit this.
[0162] The above specific implementations do not constitute a limitation on the protection scope of the present disclosure. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present disclosure shall be included in the protection scope of the present disclosure.
Claims
1. A time synchronization method, wherein: Executed by a client, the method includes: Sending a first time synchronization request to a server, and receiving time information corresponding to the first time synchronization request sent by the server; Determine a first time difference between the client and the server according to the time information; Obtaining a second time difference corresponding to a historical second time synchronization request, where the second time synchronization request is a request sent in a previous synchronization cycle; The client is time synchronized according to the first time difference and the second time difference.
2. The method according to claim 1, wherein: The method further comprises: For any time difference between the first time difference and the second time difference, obtaining a first time of the client corresponding to the time synchronization request associated with any time difference; Determining a second time fed back by the server according to the time information corresponding to any one of the time differences; A time offset between the first time and the second time is obtained as the any time difference.
3. The method according to claim 1, wherein: The performing time synchronization on the client according to the first time difference and the second time difference includes: Obtaining a third time difference between the first time difference and the second time difference; In response to the third time difference being less than a first set time value, performing time synchronization on the client based on the time information corresponding to the first time synchronization request; In response to the third time difference being greater than or equal to the first set time value, a third time synchronization request is resent to the server to reacquire time information that meets the conditions to perform time synchronization on the client.
4. The method according to any one of claims 1 to 3, wherein: The method further comprises: Determining a round trip delay of the first time synchronization request according to the time information; According to the round-trip delay, identifying anomalies in the time information; In response to the time information being in an abnormal state, the time information is discarded, and a third time synchronization request is resent to the server to reacquire time information in a normal state.
5. The method according to claim 4, wherein: The performing abnormality identification on the time information according to the round-trip delay includes: In response to the round-trip delay being greater than a second set time value, determining that the time information is in an abnormal state; In response to the round-trip delay being less than or equal to the second set time value, it is determined that the time information is in a normal state.
6. The method according to claim 4, wherein: The determining, according to the time information, a round trip delay of the first time synchronization request includes: Obtaining the receiving time of the time information; Obtaining a sending time of the first time synchronization request; The round trip delay is determined according to the receiving time and the sending time.
7. The method according to any one of claims 1 to 3, wherein: The method further comprises: The time synchronization request is retransmitted according to the set retransmission configuration information until the time information corresponding to the time synchronization request is obtained.
8. The method according to claim 7, wherein: The retransmission configuration information includes at least one parameter of the number of retransmissions and the time interval between two adjacent transmissions.
9. The method according to any one of claims 1 to 3, wherein: The method further comprises: For each time synchronization request, generating a frame header and checksum information of the time synchronization request; Based on the frame header and checksum information, the time synchronization request is generated, and the time synchronization request is sent to the server.
10. A time synchronization method, wherein: Executed by the server, the method includes: receiving a first time synchronization request and a historical second time synchronization request sent by a client, wherein the first time synchronization request and the second time synchronization request are requests sent in different synchronization cycles, and the different synchronization cycles are adjacent; Sending time information corresponding to the first time synchronization request and time information corresponding to the second time synchronization request to the client; The time information corresponding to the first time synchronization request is used to determine a first time difference between the client and the server, and the time information corresponding to the second time synchronization request is used to determine a second time difference between the client and the server. The first time difference and the second time difference are used to perform time synchronization on the client.
11. The method according to claim 10, wherein: The method further comprises: Get the frame header and checksum information from each time synchronization request; Verifying the client according to the frame header and the checksum information; After verification, time information corresponding to the time synchronization request is sent to the client.
12. A time synchronization device, executed by a client, comprising: A transceiver module, used to send a first time synchronization request to a server, and receive time information corresponding to the first time synchronization request sent by the server; A first acquisition module, used to determine a first time difference between the client and the server according to the time information; A second acquisition module, used to acquire a second time difference corresponding to a historical second time synchronization request, where the second time synchronization request is a request sent in a previous synchronization cycle; A time synchronization module is used to perform time synchronization on the client according to the first time difference and the second time difference.
13. The device according to claim 12, wherein: The device also includes: For any time difference between the first time difference and the second time difference, obtaining a first time of the client corresponding to the time synchronization request associated with any time difference; Determining a second time fed back by the server according to the time information corresponding to any one of the time differences; A time offset between the first time and the second time is obtained as the any time difference.
14. The device according to claim 12, wherein: The time synchronization module comprises: Obtaining a third time difference between the first time difference and the second time difference; In response to the third time difference being less than a first set time value, performing time synchronization on the client based on the time information corresponding to the first time synchronization request; In response to the third time difference being greater than or equal to the first set time value, a third time synchronization request is resent to the server to reacquire time information that meets the conditions to perform time synchronization on the client.
15. The device according to any one of claims 12 to 14, wherein: The device also includes: Determining a round trip delay of the first time synchronization request according to the time information; According to the round-trip delay, identifying anomalies in the time information; In response to the time information being in an abnormal state, the time information is discarded, and a third time synchronization request is resent to the server to reacquire time information in a normal state.
16. The device according to claim 15, wherein: The device comprises: In response to the round-trip delay being greater than a second set time value, determining that the time information is in an abnormal state; In response to the round-trip delay being less than or equal to the second set time value, it is determined that the time information is in a normal state.
17. The device according to claim 15, wherein: The device comprises: Obtaining the receiving time of the time information; Obtaining a sending time of the first time synchronization request; The round trip delay is determined according to the receiving time and the sending time.
18. The device according to any one of claims 12 to 14, wherein: The device also includes: The time synchronization request is retransmitted according to the set retransmission configuration information until the time information corresponding to the time synchronization request is obtained.
19. The device according to claim 18, wherein: The retransmission configuration information includes at least one parameter of the number of retransmissions and the time interval between two adjacent transmissions.
20. The device according to any one of claims 12 to 14, wherein: The device also includes: For each time synchronization request, generating a frame header and checksum information of the time synchronization request; Based on the frame header and checksum information, the time synchronization request is generated, and the time synchronization request is sent to the server.
21. A time synchronization device, executed by a server, comprising: A receiving module, configured to receive a first time synchronization request and a historical second time synchronization request sent by a client, wherein the first time synchronization request and the second time synchronization request are requests sent in different synchronization cycles, and the different synchronization cycles are adjacent; A sending module, configured to send time information corresponding to the first time synchronization request and time information corresponding to the second time synchronization request to the client; The time information corresponding to the first time synchronization request is used to determine a first time difference between the client and the server, and the time information corresponding to the second time synchronization request is used to determine a second time difference between the client and the server. The first time difference and the second time difference are used to perform time synchronization on the client.
22. The device according to claim 21, wherein The device also includes: Get the frame header and checksum information from each time synchronization request; Verifying the client according to the frame header and the checksum information; After verification, time information corresponding to the time synchronization request is sent to the client.
23. An electronic device, comprising: at least one processor; as well as a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the method of any one of claims 1-9 or 10-11.
24. A non-transitory computer-readable storage medium storing computer instructions, wherein: The computer instructions are used to cause the computer to execute the method according to any one of claims 1-9 or 10-11.
25. A computer program product comprising a computer program which, when executed by a processor, implements the steps of the method according to any one of claims 1-9 or 10-11.
Citation Information
Patent Citations
Client control method, client, electronic device, and medium
CN108696584A
Clock synchronization method, clock synchronization device and computer readable storage medium
CN110266420A
Time synchronization method and device
CN112346512A
Time synchronization method and device, electronic equipment and storage medium
CN113098646A
Data synchronization method and device, computer equipment, and storage medium
CN113961619A