代碼:
[python]
//根據返回的時間設置系統時間
void setTimeFromTP(ULONG ulTime)
{
FILETIME ft;
SYSTEMTIME st;
//將基准時間轉換成windows文件時間
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"); //別用210.72.145.44這個IP, 這是天朝的 常TMD不返回值
if (SOCKET_ERROR == ::connect(s, (sockaddr*)&servAddr, sizeof(servAddr)))
{
printf("connect error..");
return;
}
//接收時間
ULONG ulTime = 0;
int nRecv = ::recv(s, (char*)&ulTime, sizeof(ulTime), 0);
if (nRecv > 0) //收到數據
{
ulTime = ::ntohl(ulTime);
setTimeFromTP(ulTime);
}
else
{
printf("recv error...");
return;
}
::closesocket(s);
printf("*******************************");
getchar();
}
作者:xiaocaiju