Code:
[Python]
// Set the system time based on the returned Time
Void setTimeFromTP (ULONG ulTime)
{
FILETIME ft;
SYSTEMTIME st;
// Convert the reference time to the windows file time
St. wYear = 1900;
St. wMonth = 1;
St. wDay = 1;
St. wHour = 0;
St. wMinute = 0;
St. wSecond = 0;
St. wMilliseconds = 0;
SystemTimeToFileTime (& st, & ft );
LONGLONG * pLLong = (LONGLONG *) & ft;
* PLLong + = (LONGLONG) 10000000 * ulTime;
FileTimeToSystemTime (& ft, & st );
: SetSystemTime (& st );
}
Void main ()
{
CInitSock initSock;
SOCKET s =: socket (AF_INET, SOCK_STREAM, IPPROTO_TCP );
If (s = INVALID_SOCKET)
{
Printf ("socket error ...");
Return;
}
Sockaddr_in servAddr = {0 };
ServAddr. sin_family = AF_INET;
ServAddr. sin_port =: htons (37 );
ServAddr. sin_addr.S_un.S_addr =: inet_addr ("69.25.96.13"); // do not use the 210.72.145.44 IP address, which is a common TMD value not returned by tianchao.
If (SOCKET_ERROR =: connect (s, (sockaddr *) & servAddr, sizeof (servAddr )))
{
Printf ("connect error ..");
Return;
}
// Receipt time
ULONG ulTime = 0;
Int nRecv =: recv (s, (char *) & ulTime, sizeof (ulTime), 0 );
If (nRecv> 0) // receives data
{
UlTime =: ntohl (ulTime );
SetTimeFromTP (ulTime );
}
Else
{
Printf ("recv error ...");
Return;
}
: Closesocket (s );
Printf ("*******************************");
Getchar ();
}
Author: xiaocaiju