網路對時程式

2021-04-02 12:22:50 字數 3649 閱讀 7755

程式幫助:

typedef struct _systemtime systemtime;

thefiletimestructure is a 64-bit value representing the number of 100-nanosecond intervals since january 1, 1601.

typedef struct _filetime filetime

thefiletimetosystemtimefunction converts a 64-bit file time to system time format. 

bool filetimetosystemtime(

const filetime*lpfiletime,// pointer to file time to convertlpsystemtimelpsystemtime // pointer to structure to receive

// system time);

//源程式
#define win32_lean_and_mean

#include

#include 

#include

#include

#include

#include

#pragma comment (lib,"ws2_32")

#define unicode

#define _unicode

#define _countof(array) (sizeof(array)/sizeof(array[0]))

#define hightime  21968699 // 21968708 // jan 1, 1900 filetime.hightime

#define lowtime   4259332096 // 1604626432 // jan 1, 1900 filetime.lowtime

using namespace std;//ntp伺服器列表

struct nistsvr nistsvrsary = , null, null},

, _t("time-a.nist.gov"),_t("nist,蓋士堡,馬里蘭州") },

, _t("time-b.nist.gov"),_t("nist,蓋士堡,馬里蘭州") },

, _t("time-a.timefreq.bldrdoc.gov"),_t("nist,博耳德市,科羅拉多州") },

, _t("time-b.timefreq.bldrdoc.gov"),_t("nist,博耳德市,科羅拉多州") },

, _t("time-c.timefreq.bldrdoc.gov"),_t("nist,博耳德市,科羅拉多州") },

, _t("tutcnist.colorado.edu"),_t("科羅拉多大學,博耳德市") },

, _t("time.nist.gov"),_t("ncar,博耳德市,科羅拉多州") },

, _t("time-nw.nist.gov"),_t("microsoft,雷蒙德,華盛頓州") },

, _t("nist1.nyc.certifiedtime.com"),_t("abovnet,紐約市") },

};//所選擇的ntp伺服器

static int choice = 0;

void usage()

}bool updatesystime(dword dwtime)

bool gettimefromserver(dword *lpdwtime)

if(4 == iread)

else

printf( "    error getting time!/n");

}else

printf( "    ***connection failed***/n");

closesocket(ssock);

}return breturn;

}int main(int argc,char *argv)

if(argc<2)

else

choice = atoi(&argv[1][strlen(argv[1])-1]);

dword dwtime;

//取伺服器時間

if (gettimefromserver(&dwtime))

else

}wsacleanup();

return 0;

}

//ntp伺服器列表

struct nistsvr nistsvrsary = , null, null},

, _t("time-a.nist.gov"),_t("nist,蓋士堡,馬里蘭州") },

, _t("time-b.nist.gov"),_t("nist,蓋士堡,馬里蘭州") },

, _t("time-a.timefreq.bldrdoc.gov"),_t("nist,博耳德市,科羅拉多州") },

, _t("time-b.timefreq.bldrdoc.gov"),_t("nist,博耳德市,科羅拉多州") },

, _t("time-c.timefreq.bldrdoc.gov"),_t("nist,博耳德市,科羅拉多州") },

, _t("tutcnist.colorado.edu"),_t("科羅拉多大學,博耳德市") },

, _t("time.nist.gov"),_t("ncar,博耳德市,科羅拉多州") },

, _t("time-nw.nist.gov"),_t("microsoft,雷蒙德,華盛頓州") },

, _t("nist1.nyc.certifiedtime.com"),_t("abovnet,紐約市") },

};//所選擇的ntp伺服器

static int choice = 0;

void usage()

}bool updatesystime(dword dwtime)

bool gettimefromserver(dword *lpdwtime)

if(4 == iread)

else

printf( "    error getting time!/n");

}else

printf( "    ***connection failed***/n");

closesocket(ssock);

}return breturn;

}int main(int argc,char *argv)

if(argc<2)

else

choice = atoi(&argv[1][strlen(argv[1])-1]);

dword dwtime;

//取伺服器時間

if (gettimefromserver(&dwtime))

else

}wsacleanup();

return 0;

}

網路遊戲的對時以及同步問題

大多數實時網路遊戲,將 server 的時間和 client 的時間校對一致是可以帶來許多其他系統設計上的便利的。這裡說的對時,並非去調整 client 的 os 中的時鐘,而是把 game client 內部的邏輯時間調整跟 server 一致即可。一個粗略的對時方案可以是這樣的,client 發...

網路遊戲的對時以及同步問題

大多數實時網路遊戲,將server 的時間和 client 的時間校對一致是可以帶來許多其他系統設計上的便利的。這裡說的對時,並非去調整 client 的os 中的時鐘,而是把 game client 內部的邏輯時間調整跟 server 一致即可。一個粗略的對時方案可以是這樣的,client 發一個...

網路遊戲的對時以及同步問題

from 網路遊戲的對時以及同步問題 大多數實時網路遊戲,將 server 的時間和 client 的時間校對一致是可以帶來許多其他系統設計上的便利的。這裡說的對時,並非去調整 client 的 os 中的時鐘,而是把 game client 內部的邏輯時間調整跟 server 一致即可。一個粗略的...

網路遊戲的對時以及同步問題

大多數實時網路遊戲,將 server 的時間和 client 的時間校對一致是可以帶來許多其他系統設計上的便利的。這裡說的對時,並非去調整 client 的 os 中的時鐘,而是把 game client 內部的邏輯時間調整跟 server 一致即可。一個粗略的對時方案可以是這樣的,client 發...

雲風 網路遊戲的對時以及同步問題

大多數實時網路遊戲,將 server 的時間和 client 的時間校對一致是可以帶來許多其他系統設計上的便利的。這裡說的對時,並非去調整 client 的 os 中的時鐘,而是把 game client 內部的邏輯時間調整跟 server 一致即可。一個粗略的對時方案可以是這樣的,client 發...