Simple NTP Client?

This is a discussion on Simple NTP Client? within the Networking/Device Communication forums, part of the General Programming Boards category; Hi there I'm trying to build an application which has the ability to connect to a public NTP or SNTP ...

  1. #1
    Registered User
    Join Date
    Apr 2006
    Posts
    5

    Question Simple NTP Client?

    Hi there

    I'm trying to build an application which has the ability to connect to a public NTP or SNTP server to get the correct time.

    I've been reading the RFC's but quite honestly they're over complicated for my needs.

    Leep-Seconds? Pico-Seconds? For the purposes of what I'm doing I would be happy to get a time-stamp which is accurate to within 1 minute.

    Does anyone have a simple example of how to query a public server for time without worrying about latency?

    Cheers

  2. #2
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    you could always use your system time and just make sure that's kept in check... you could probably even leave the syncrhonization to twice a month if all you need is +/-60 second's accuracy...
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  3. #3
    Registered User
    Join Date
    Apr 2006
    Posts
    5
    That's true.. I should explain what I'm trying to do..

    I'm making a de-centralised network..

    Each node needs to grab the time from a public NTP server

    Every 5 minutes every node in the network needs to make a switch.. if they go more than 5 minutes apart they will lose the entire network.

    So there are many different solutions to the problem,

    1. Regularly update the system clock using an existing NTP client

    2. Regularly update the system clock using the application to connect to an NTP server

    3. Regularly update the application time from an NTP server

    The major problem is that the network is decentralised and needs to use publicly avaliable NTP servers.

    The second problem is that distributing an existing NTP client with the application isn't really an option..

    Basically what I want the application to do is:

    Open UDP port 123
    Send a request to the public NTP server for the current time

    I know how to do UDP in C++..

    I don't know how to request the time from the NTP server


  4. #4
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    well, did you look into NIST's time servers and standards specifications?

    NIST servers
    timesetting protocols

    I'm not sure how much that will help you, as I've never done something like this myself, but hopefully it'll at least be of some use to you.
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  5. #5
    Registered User
    Join Date
    Apr 2006
    Posts
    5
    Thanks Major_Small,

    Looks like NIST run on NTP servers..

    I've been talking with a lot of people about this and there are some other options.

    Run SNTP instead which is suppose to be a simpler protocol which can access NTP servers.

    Use either the TIME (RFC 838) or DAYTIME protocols however it would be very hard to find a public server running this software these days.

    Use an existing NTP/SNTP client (unfortunately this isn't really a solution I can use.. although much simpler!)

    -------------

    I've worked out that all I need to do is send an NTP Packet to an NTP server via UDP and I will get one back containing the server time.

    The first 32 bits of the NTP time stamp format are the unix epoch + 0x83aa7e80 <-- this is the magic 32 bits I'm trying to get my hands on!

    -------------

    Anyways I'm still working on this, if anyone has any more suggestions I'm all ears

  6. #6
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,452
    So which OS/Compiler are you using?

    I imagine there are plenty of NTP clients out there.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  7. #7
    Registered User
    Join Date
    Mar 2006
    Posts
    6
    If your not too worried about precision, maybe consider doing a HEAD HTTP request to some server of your choice, and parsing the time from the Date: header.

    I know its not NTP, but it may work for your purposes......

  8. #8
    Registered User
    Join Date
    Apr 2006
    Posts
    5
    Quote Originally Posted by Salem
    So which OS/Compiler are you using?

    I imagine there are plenty of NTP clients out there.
    C++ Compiler.. I've looked into that as an idea, I have found one class which will probably work...

    Quote Originally Posted by NogginTheNog
    If your not too worried about precision, maybe consider doing a HEAD HTTP request to some server of your choice, and parsing the time from the Date: header.

    I know its not NTP, but it may work for your purposes......
    I think you just found me an easy alternative! Can you give me a bit more information about that?

    Do all http headers contain the server date?..

    Cheers

  9. #9
    * Death to Visual Basic * Devil Panther's Avatar
    Join Date
    Aug 2001
    Posts
    768
    If you need a simple NTP client without the need of going through hell of RFC, I suggest you use a sniffer to copy the traffic of some ready NTP client!
    "I don't suffer from insanity but enjoy every minute of it" - Edgar Allen Poe

    http://www.Bloodware.net - Developing free software for the community.

  10. #10
    Registered User kryptkat's Avatar
    Join Date
    Dec 2002
    Posts
    638

  11. #11
    Registered User
    Join Date
    Apr 2006
    Posts
    5
    Quote Originally Posted by Devil Panther
    If you need a simple NTP client without the need of going through hell of RFC, I suggest you use a sniffer to copy the traffic of some ready NTP client!
    genious!

  12. #12
    * Death to Visual Basic * Devil Panther's Avatar
    Join Date
    Aug 2001
    Posts
    768
    always remember, Ethereal is your friend!
    "I don't suffer from insanity but enjoy every minute of it" - Edgar Allen Poe

    http://www.Bloodware.net - Developing free software for the community.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 40
    Last Post: 09-01-2006, 12:09 AM
  2. Looking for coder: Simple C++ Client / Server game
    By kocho in forum Projects and Job Recruitment
    Replies: 1
    Last Post: 02-04-2006, 01:34 PM
  3. Client - PLEASE HELP!
    By markpratt in forum C++ Programming
    Replies: 6
    Last Post: 12-14-2003, 11:08 PM
  4. Client timed-out once on connect(), can never connect() again
    By registering in forum Networking/Device Communication
    Replies: 6
    Last Post: 10-28-2003, 02:46 PM
  5. simple client
    By stryker1080 in forum Networking/Device Communication
    Replies: 1
    Last Post: 10-13-2003, 12:12 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21