局域网内时间的同步?谢谢!
server:
建一个thread,一旦客户段需要同步,则给event置位,启动thread
thread里可以有以下的代码
char sBuff[256];
memset(sBuff,0,256);
SYSTEMTIME time;
GetLocalTime(&time);
sprintf(sBuff,"Set Time%4d%2d%2d%2d%2d%2d",
time.wYear,time.wMonth,time.wDay,
time.wHour,time.wMinute,time.wSecond);
int nBytesSent;
if((nBytesSent = send(sockTemp, sBuff, strlen(sBuff), 0)) == SOCKET_ERROR)
{
AfxMessageBox("SEND FAILED!");
}
client:
只要连接server,循环等待,准备接收时间数据就行