Client-Server problem - send timestamp

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Mar 2008
Posts: 42
Reputation: marcosjp is an unknown quantity at this point 
Solved Threads: 0
marcosjp marcosjp is offline Offline
Light Poster

Client-Server problem - send timestamp

 
0
  #1
Aug 26th, 2008
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!
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 1,669
Reputation: jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of 
Solved Threads: 123
jephthah's Avatar
jephthah jephthah is offline Offline
Posting Virtuoso

Re: Client-Server problem - send timestamp

 
0
  #2
Aug 26th, 2008
i dont understand your question.

you want to send the number of seconds?

well.... the number of seconds of "what"?
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 169
Reputation: murderotica is an unknown quantity at this point 
Solved Threads: 2
murderotica's Avatar
murderotica murderotica is offline Offline
Junior Poster

Re: Client-Server problem - send timestamp

 
-1
  #3
Aug 27th, 2008
You got the time in string and you want to manipulate it?
An Avalanche In D Minor
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 376
Reputation: Clockowl is on a distinguished road 
Solved Threads: 27
Clockowl's Avatar
Clockowl Clockowl is offline Offline
Posting Whiz

Re: Client-Server problem - send timestamp

 
0
  #4
Aug 27th, 2008
You can use atoi() for converting "ASCII" to "integer".
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,649
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1498
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is online now Online
Still Learning

Re: Client-Server problem - send timestamp

 
0
  #5
Aug 27th, 2008
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.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 2,001
Reputation: ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of 
Solved Threads: 343
ArkM's Avatar
ArkM ArkM is offline Offline
Postaholic

Re: Client-Server problem - send timestamp

 
0
  #6
Aug 28th, 2008
How about transmission delay? See, for example:
http://en.wikipedia.org/wiki/Network_Time_Protocol
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C Forum


Views: 991 | Replies: 5
Thread Tools Search this Thread



Tag cloud for C
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC