C + + Builder The TIDSNTP component gets Internet time __c++

Source: Internet
Author: User

C + + Builder lower TIDSNTP control get Internet time

C + + Builder integrates a set of networked controls, which are powerful, where TIDSNTP is used to get standard time on the Internet, and the following is a brief introduction to the use of the component.

XP under the clock there are several times the server can take advantage of, bring into the idsntp1->host can find, for example, multithreading under the same time to obtain the first access to.

time.windows.com

time.nist.gov (This looks faster)

time-nw.nist.gov

time-a.nist.gov

The code is as follows:

Port of the time server

#define SNTPPORT 123
Receive timeout unit seconds
#define Receivetimeoutsecond 10
Client Send time Timeout
#define Sendtimeoutsecond 5

Try
{
School Time Device
TIDSNTP *IDSNTP1 = new TIDSNTP (NULL);
Connecting hosts
Idsntp1->host = "time.nist.gov";
Idsntp1->port = Sntpport;
milliseconds multiplied by 1000 to seconds
Idsntp1->receivetimeout = receivetimeout * 1000;

Idsntp1->active = true;
If the connection is normal
Try
{
if (idsntp1->synctime () = = True)
{

Successful acquisition of Time
Tdatetime remotedate = idsntp1->datetime;
}
}
catch (...) __finally
{

// ...
}
Delete IdSNTP1;
}
__finally
{
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.