I am currently working on a project that will act like a Online selling website such as Amazon, or Ebay in a very small scale. I was wondering if anyone could point me in the right direction on how to use Timers for C++. Learnin开发者_运维百科g Socket Programming at the moment, and was trying to incorporate the timer for the auction time when someone is selling their product.
Thanks
You mean like timer_create?
How are you handling your sockets? Threads or select
? If the latter (or something like select), timer_create will be a natural fit.
C++ does not have built-in timers. What libraries you are willing to use really makes the difference in your answer.
Operating systems will have built-in timers, other libraries like Boost (mentioned in another answer), or toolkits like Qt or runtime systems like .NET will also have timers available.
I recommend you describe your environment in more detail before moving on.
What are you using for the Sockets? If it's a relatively well-known API, it will likely have a timer implementation as well. side note: You'll also want to look into threads to use for your sockets.
boost::asio timers, or the boost timer library (http://www.boost.org/doc/libs/1_40_0/libs/timer/index.html). Or just use the native OS timer functionalities, e.g., in Windows it'll be SetTimer and KillTime.
精彩评论