Jump to content
  • Advertisement
Sign in to follow this  
Triad_prague

getting time from a time server

This topic is 2537 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, my CMOS battery socket is damaged and so, my PC won't show the correct time every time I start it up (it will always show 01/01/2002 00:00 AM which I think is the time and date the motherboard created). I found it quite annoying to have to set the time to correct value every time I boot my PC, and I came up with an idea to make a small app to get time from a time server and set the system time accordingly. thing is, I forgot how to do that. I remember ever creating such a program when I was learning networking (Winsock) for the first time. IIRC, it used UDP socket, I forgot the port number, and I forgot the time server address. So in my humble confusion I beg you, if anyone can, to give hints on how it can be done.

to sum it up, what I need is a guide to:
-how to get time from the time server, and the requirements (what message to send, etc)

Thanks :D

Share this post


Link to post
Share on other sites
Advertisement

... thing is, I forgot how to do that. I remember ever creating such a program when I was learning networking (Winsock) for the first time. IIRC, it used UDP socket, I forgot the port number, and I forgot the time server address. So in my humble confusion I beg you, if anyone can, to give hints...


Maybe you're referring to NTP? http://www.nist.gov/pml/div688/grp40/its.cfm

If so, googling a few terms from there should lead you to numerous examples and information - more than we can suggest here :)

Share this post


Link to post
Share on other sites
I solved it. I use the simplistic TIME protocol by:
-connect()-ing to time server on port 37
-recv() 4 bytes and copy it to 32 bit unsigned integer and translate the byte order using ntohl()
-since the returned value is seconds since 1 jan 1900, convert it to suits my need and I'm done

I hope it can be helpful for those who seek similar information, thanks and see ya :wink:

Share this post


Link to post
Share on other sites
For the record, any recent version of Windows can be configured to sync clocks to an NTP server automatically. How exactly you do it depends on your particular setup, but try right clicking on the clock in the notification area ;-)

Share this post


Link to post
Share on other sites
@ApochPiQ, the built-in time synchronization in windows only works if the date/time isn't too much different. It doesn't work if my PC date is 9 years left behind (which will always be since the CMOS battery socket's blasted)...that's why I needed to create my own tool for that :)

Share this post


Link to post
Share on other sites

@ApochPiQ, the built-in time synchronization in windows only works if the date/time isn't too much different. It doesn't work if my PC date is 9 years left behind (which will always be since the CMOS battery socket's blasted)...that's why I needed to create my own tool for that :)


Cygwin comes with ntpdate. You can add this to a startup script:

ntpdate -q pool.ntp.org

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!