best way to create clock from remote server

R

roughtrader

Hello,

I have a function that retrieves the epoch time from a remote server.
Let's say it's: time_t retrieveTime();

I have an MFC application, and I want to continually update a time_t
variable using the function retrieveTime(), in order to build a clock
with 1-second resolution from the remote server.

I can't use a while loop because the enclosing function would never
release control of the application, and that would defeat the point of
having an application.

What I *think* should be done is to create a timer that starts
counting once the application is launched. The resolution on the
timer could be as fast as 1 millisecond. Each time the timer updates,
retrieveTime() could be called and the value stored in a variable.

Basically, I want to build this clock and keep it "out of the way" of
the main application. Am I on the right track here? Can someone
suggest some code that would help get me started?

thanks,

rt
 
A

Alf P. Steinbach

* roughtrader:
Hello,

I have a function that retrieves the epoch time from a remote server.
Let's say it's: time_t retrieveTime();

I have an MFC application, and I want to continually update a time_t
variable using the function retrieveTime(), in order to build a clock
with 1-second resolution from the remote server.

I can't use a while loop because the enclosing function would never
release control of the application, and that would defeat the point of
having an application.

What I *think* should be done is to create a timer that starts
counting once the application is launched. The resolution on the
timer could be as fast as 1 millisecond. Each time the timer updates,
retrieveTime() could be called and the value stored in a variable.

Basically, I want to build this clock and keep it "out of the way" of
the main application. Am I on the right track here? Can someone
suggest some code that would help get me started?

Timer idea is good, calling a remote server 1000 times per second is bad.

But for more details please ask in a Microsoft-specific group.

The question is off-topic in [comp.lang.c++] (see the FAQ and/or the welcome
message for some group suggestions and what's regarded as on-topic).


Cheers & hth.,

- Alf
 
J

Jorgen Grahn

Hello,

I have a function that retrieves the epoch time from a remote server.
Let's say it's: time_t retrieveTime();

I have an MFC application, and I want to continually update a time_t
variable using the function retrieveTime(), in order to build a clock
with 1-second resolution from the remote server.

Why? Epoch time is either broken or pretty much the same everywhere,
in which case you can just use the local machine's clock. Are you
doing this because you suspect the remote machine's clock drifts,
jumps et cetera?

Also note that you do not have control over network latency.

Sorry for being offtopic, but there's a chance that programming is the
wrong tool for solving your problem.

/Jorgen
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,521
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top