0

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!

6
Contributors
5
Replies
6
Views
9 Years
Discussion Span
Last Post by ArkM
0

i dont understand your question.

you want to send the number of seconds?

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

0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.