Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5846133
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:32:02+00:00 2026-05-22T12:32:02+00:00

I’m looking for a simple clock synchronization protocol that would be easy to implement

  • 0

I’m looking for a simple clock synchronization protocol that would be easy to implement with small footprint and that would work also in the absence of internet connection, so that it could be used e.g. within closed laboratory networks. To be clear, I’m not looking for something that can be used just to order events (like vector clocks), but something that would enable processes on different nodes to synchronize their actions based on local clocks. As far as I understand, this would require a solution that can take clock drift into account. Presence of TCP/IP or similar relatively low-latency stream connections can be assumed.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T12:32:03+00:00Added an answer on May 22, 2026 at 12:32 pm

    Disclaimer: I’m not an NTP expert by any means. Just a hobbyist having fun on the weekend.

    I realize you said you didn’t want an NTP implementation, because of the perceived complexity and because an Internet NTP server may not be available in your environment.

    However, an simplified NTP look-up may be easy to implement, and if you have a local NTP server you can achieve good synchronization.

    Here’s how:

    Review RFC 5905

    You’ll see NTP v4 packets look something like:

    • LI (2 bits)
    • VN (3 bits) – Use ‘100’ (4)
    • Mode (3 bits)
    • Stratum (8 bits)
    • Poll (8 bits)
    • Precision (8 bits)
    • Root Delay (32 bits)
    • Root Dispersion (32 bits)
    • Reference Id (32 bits)
    • Reference Timestamp (64 bits)
    • Origin Timestamp (64 bits)
    • Receive Timestamp (64 bits)
    • Transmit Timestamp (64 bits)
    • Extension Field 1 (variable)
    • Extension Field 2 (variable)
    • …
    • Key Identifier
    • Digest (128 bits)

    The digest is not required, so forming a valid client request is very easy. Following the guidance in the RFC, use LI = ’00’, VN = ‘100’ (decimal 4), Mode = ‘011’ (decimal 3).

    Using C# to illustrate:

    byte[] ntpData = new byte[48]
    Array.Clear(ntpData, 0, ntpData.Length);
    ntpData[0] = 0x23;  // LI = 00, VN = 100, Mode = 011
    

    Open a socket to your target server and send it over.

    int ntpPort = 123;
    IPEndPoint target = new IPEndPoint(Dns.GetHostEntry(serverDnsName).AddressList[0], ntpPort);
    Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
    s.Connect(target);
    s.Send(ntpData);
    

    In the response, the current time will be in the Transmit Timestamp (bytes [40 – 48]). Timestamps are 64-bit unsigned fixed-point numbers. The integer part is the first 32 bits, the fractional part is the last 32 bits. It represents the number of seconds since 0h on Jan-1-1900.

    s.Receive(ntpData);
    s.Close();
    
    ulong intPart = 0;
    ulong fractPart = 0;
    
    for (int i = 0; i < 4; i++)
        intPart = (intPart << 8) | ntpData[40 + i];
    
    for (int i = 4; i < 8; i++)
        fractPart = (fractPart << 8) | ntpData[40 + i];
    

    To update the clock with (roughly) second granularity, use: # of seconds since 0h Jan-1-1900 = intPart + (fractPart / 2^32). (I say roughly because network latency isn’t accounted for, and we’re rounding down here)

    ulong seconds = intPart + (fractPart / 4294967296);
    
    TimeSpan ts = TimeSpan.FromTicks((long)seconds * TimeSpan.TicksPerSecond);
    
    DateTime now = new DateTime(1900, 1, 1);
    now = DateTime.SpecifyKind(now, DateTimeKind.Utc);
    now += ts;
    

    "now" is now a DateTime with the current time, in UTC.

    While this might not answer your question, hopefully it makes NTP a little less opaque. =)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I'm looking for suggestions for debugging... If you view this site in Firefox or
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Seemingly simple, but I cannot find anything relevant on the web. What is the
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I want to count how many characters a certain string has in PHP, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.