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
{
}