954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Client-Server problem - send timestamp

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:

time_t now;
struct tm* myTime;

now = time(NULL); 
myTime = localtime(&now);

strcpy(msgTime, asctime(myTime));
int msgSize = strlen(msgTime);

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!

marcosjp
Light Poster
43 posts since Mar 2008
Reputation Points: 10
Solved Threads: 0
 

i dont understand your question.

you want to send the number of seconds?

well.... the number of seconds of "what"?

jephthah
Posting Maven
2,587 posts since Feb 2008
Reputation Points: 2,143
Solved Threads: 179
 

You got the time in string and you want to manipulate it?

murderotica
Junior Poster
171 posts since Aug 2008
Reputation Points: 7
Solved Threads: 2
 

You can use atoi() for converting "ASCII" to "integer". :)

Clockowl
Posting Whiz
376 posts since May 2008
Reputation Points: 69
Solved Threads: 28
 

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().

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

How about transmission delay? See, for example:
http://en.wikipedia.org/wiki/Network_Time_Protocol
;)

ArkM
Postaholic
2,001 posts since Jul 2008
Reputation Points: 1,234
Solved Threads: 348
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You