read the server time

This is a discussion on read the server time within the C++ Programming forums, part of the General Programming Boards category; how can a system that connected to server can be set to the same exactly same as the server? normally ...

  1. #1
    Registered User
    Join Date
    Nov 2006
    Posts
    23

    read the server time

    how can a system that connected to server can be set to the same exactly same as the server? normally that a program run at the local system, we would be able to read from local system (the time we set in computer) but how if we want to synchornous to the server time?

  2. #2
    coder
    Join Date
    Feb 2008
    Posts
    127
    I'm a bit confused with your question. What you exactly want/need to do? May you give an example?

  3. #3
    Registered User
    Join Date
    Nov 2006
    Posts
    23
    let say now I have a pc that connecting to a server. my pc's time is 10 Jan 2008 whereas the server's time is 12 Jan 2008. So now I want to read the time from server.

  4. #4
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    I suppose your server should support corresponding request
    http://www.google.co.il/search?hl=en...est+servertime
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  5. #5
    Registered User
    Join Date
    Nov 2006
    Posts
    23
    yes... actually i have this device that go under testing. so each time, i will need to manually change the time and date of that device to syn. with my pc local time. but indeed of using local pc time, I will wish to use the server time so it will be more accurate as local pc time might be changed by others and incorrect!
    so basically i am developing a program that will automatically take the time from server and update the the device.

    I have ady get this function
    NetRemoteTOD
    but somehow it could work with my compiler...

    any idea?

  6. #6
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,265
    Is the server running a NTP server? If so, then just use that.

  7. #7
    Registered User
    Join Date
    Nov 2006
    Posts
    23
    how if no... can it be more simple than that?

  8. #8
    coder
    Join Date
    Feb 2008
    Posts
    127
    1- when a the server receives a remote connection, it sends the serv time.
    2- the client gets it, compare with its local time and adjusts if it's the case.
    I cannot see a simpler way than this

  9. #9
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,059
    Quote Originally Posted by carlyn View Post
    yes... actually i have this device that go under testing. so each time, i will need to manually change the time and date of that device to syn. with my pc local time. but indeed of using local pc time, I will wish to use the server time so it will be more accurate as local pc time might be changed by others and incorrect!
    so basically i am developing a program that will automatically take the time from server and update the the device.

    I have ady get this function
    NetRemoteTOD
    but somehow it could work with my compiler...

    any idea?
    Possibly?

    Code:
    #pragma comment(lib, "netapi32.lib")
    #include <stdio.h>
    #include <windows.h>
    #include <lm.h>
    
    static const char *dow[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
    static const char *month[] = { "???", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
    
    int main( int argc, char *argv[] )
    {
    	wchar_t server[256] = L"";
    	TIME_OF_DAY_INFO *p = NULL;
    
    	if ( argc > 1 )
    		mbstowcs( server, argv[1], strlen( argv[1] ) + 1 );
    	else
    		return -1;
    	if(NetRemoteTOD( server, (LPBYTE *) &p ) != NERR_Success)
    		return -1;
    	printf( "Unix time_t:     %lu (since 1/1/70 00:00:00 UTC)\n", p->tod_elapsedt );
    	printf( "Milliseconds:    %lu (since boot)\n", p->tod_msecs );
    	printf( "Current time:    %02lu:%02lu:%02lu.%02lu (UTC)\n", p->tod_hours, p->tod_mins, p->tod_secs, p->tod_hunds );
    	printf( "Timezone offset: %ld (minutes from GMT)\n", p->tod_timezone );
    	printf( "Tick length:     %lu (microseconds)\n", p->tod_tinterval * 100 );
    	printf( "Current date:    %s, %lu %s %lu\n", dow[p->tod_weekday], p->tod_day, month[p->tod_month], p->tod_year );
    	NetApiBufferFree( p ); 
    	return 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. server client application - (i really need your help)
    By sarahnetworking in forum C Programming
    Replies: 3
    Last Post: 03-01-2008, 10:54 PM
  2. Multi-Threaded Server Help
    By jonswits20 in forum C# Programming
    Replies: 5
    Last Post: 04-18-2007, 12:05 AM
  3. The Timing is incorret
    By Drew in forum C++ Programming
    Replies: 5
    Last Post: 08-28-2003, 05:57 PM
  4. IE 6 status bar
    By DavidP in forum Tech Board
    Replies: 15
    Last Post: 10-23-2002, 06:31 PM
  5. give user time to read messages
    By Shadow in forum C Programming
    Replies: 2
    Last Post: 04-21-2002, 01:54 AM

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