| | |
Client-Server problem - send timestamp
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Mar 2008
Posts: 42
Reputation:
Solved Threads: 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:
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!
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:
c Syntax (Toggle Plain Text)
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!
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.
![]() |
Other Threads in the C Forum
- Previous Thread: A newbie poSter,needs help in adding & subtracting binary digits...
- Next Thread: Help
Views: 991 | Replies: 5
| Thread Tools | Search this Thread |
Tag cloud for C
adobe ansi api array arrays bash binarysearch centimeter char convert copyanyfile copypdffile cprogramme createcopyoffile createprocess() csyntax directory drawing dynamic executable fflush file fork frequency getlasterror givemetehcodez global graphics gtkgcurlcompiling hardware highest homework i/o inches infiniteloop initialization interest km lazy linked linkedlist linux linuxsegmentationfault list locate logical_drives match matrix meter microsoft motherboard multi mysql open opendocumentformat opensource openwebfoundation owf pattern pdf performance pointer pointers posix power problem probleminc program programming pyramidusingturboccodes read recursion recv repetition scanf scheduling segmentationfault send shape socketprograming spoonfeeding stack standard strchr string strings structures student suggestions system systemcall test testautomation unix user voidmain() wab win32 win32api windows.h






