943,750 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 1442
  • C RSS
Aug 26th, 2008
0

Client-Server problem - send timestamp

Expand Post »
Hello there!

I've built a simple server and a simple client in C (Linux).
Among other tasks, I need the server to send the timestamp (using time.h) to the client.
Then I need the client to change the system time based on the timestamp received from the server.

What would be the best way?
I already get the timestamp in the client, but as a string after using asctime, this way:

  1. time_t now;
  2. struct tm* myTime;
  3.  
  4. now = time(NULL);
  5. myTime = localtime(&now);
  6.  
  7. strcpy(msgTime, asctime(myTime));
  8. int msgSize = strlen(msgTime);
  9.  
  10. send(sockCli, msgTime, msgSize, 0);

But this is just a string...
Is there a way of receiving the number of seconds in the client and thus making it a lot easier to do time operations? How?

Thank you for any hints!
Reputation Points: 10
Solved Threads: 0
Light Poster
marcosjp is offline Offline
42 posts
since Mar 2008
Aug 26th, 2008
0

Re: Client-Server problem - send timestamp

i dont understand your question.

you want to send the number of seconds?

well.... the number of seconds of "what"?
Reputation Points: 2143
Solved Threads: 178
Posting Maven
jephthah is offline Offline
2,567 posts
since Feb 2008
Aug 27th, 2008
-1

Re: Client-Server problem - send timestamp

You got the time in string and you want to manipulate it?
Reputation Points: 7
Solved Threads: 2
Junior Poster
murderotica is offline Offline
171 posts
since Aug 2008
Aug 27th, 2008
0

Re: Client-Server problem - send timestamp

You can use atoi() for converting "ASCII" to "integer".
Reputation Points: 69
Solved Threads: 28
Posting Whiz
Clockowl is offline Offline
376 posts
since May 2008
Aug 27th, 2008
0

Re: Client-Server problem - send timestamp

Instead of sending the string returned by asctime() why now just convert the integer returned by time() to a string and send that? Then on client side just convert back to int and use it to change the computer's clock. If client needs the string returned by asctime() then it can get it itself from the string you send that was returned by time().
Last edited by Ancient Dragon; Aug 27th, 2008 at 9:58 am.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,950 posts
since Aug 2005
Aug 28th, 2008
0

Re: Client-Server problem - send timestamp

How about transmission delay? See, for example:
http://en.wikipedia.org/wiki/Network_Time_Protocol
Reputation Points: 1234
Solved Threads: 347
Postaholic
ArkM is offline Offline
2,001 posts
since Jul 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: A newbie poSter,needs help in adding & subtracting binary digits...
Next Thread in C Forum Timeline: Help





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC