|
本帖最后由 道易有道 于 2023-3-9 09:12 编辑
|
时间_取NTP服务器时间戳 | 长整数型 | | |
NTP服务器 | 文本型 | | | | 是否精确毫秒戳 | 逻辑型 | | | |
变量名 | 类 型 | 静态 | 数组 | 备 注 | NtpName | 文本型 | | | wsaData | 套接字信息 | | | hints | 整数型 | | | ai_list | 整数型 | | | ai_family | 整数型 | | | ai_socktype | 整数型 | | | ai_protocol | 整数型 | | | sock | 整数型 | | | ai_addrlen | 整数型 | | | ai_addr | 整数型 | | | dwBufLen | 整数型 | | | ntpBuf | 整数型 | | | iRes | 整数型 | | | readfds | 整数型 | | | timeout | 字节集 | | | nTimestampSeconds | 整数型 | | | nTimestampFractions | 整数型 | | | nlTime | 长整数型 | | | 如果 (是否为空 (NTP服务器 )) NtpName = “time.windows.com”NtpName = NTP服务器 nlTime = #INVALID_SOCKET 如果真 (WSAStartup (合并短整数 (1, 1 ), wsaData ) = #ERROR_SUCCESS )hints = LocalAlloc ( #LMEM_ZEROINIT, 32 ) __set (hints, 4, #AF_UNSPEC )__set (hints, 8, #SOCK_DGRAM )__set (hints, 12, #IPPROTO_UDP ) 如果真 (getaddrinfo (NtpName, “123”, hints, 取指针整数_ (ai_list )) = #ERROR_SUCCESS )ai_family = __get (ai_list, 4 )ai_socktype = __get (ai_list, 8 )ai_protocol = __get (ai_list, 12 )sock = socket (ai_family, ai_socktype, ai_protocol )如果真 (sock ≠ #INVALID_SOCKET )ai_addrlen = __get (ai_list, 16 )ai_addr = __get (ai_list, 24 )dwBufLen = 48 ntpBuf = LocalAlloc ( #LMEM_ZEROINIT, dwBufLen )__set (ntpBuf, 0, 27 )iRes = sendto1 (sock, ntpBuf, dwBufLen, 0, ai_addr, ai_addrlen )如果真 (iRes = dwBufLen )readfds = LocalAlloc ( #LMEM_ZEROINIT, 260 ) __set (readfds, 0, 1 )__set (readfds, 4, sock )timeout = { 3, 0, 0, 0, 0, 0, 0, 0 } iRes = select1 (sock + 1, readfds, #NULL, #NULL, 取指针_字节集型 (timeout )) 如果真 (iRes > 0 )memset (ntpBuf, 0, dwBufLen )iRes = recvfrom1 (sock, ntpBuf, dwBufLen, 0, ai_addr, ai_addrlen )如果真 (iRes = dwBufLen )nTimestampSeconds = __get (ntpBuf, 40 )nlTime = 整数_有符号转无符号 (ntohl (nTimestampSeconds )) - 2208988800 如果真 (是否精确毫秒戳 )nTimestampFractions = __get (ntpBuf, 44 )nlTime = nlTime × 1000 nlTime = nlTime + 整数_有符号转无符号 (ntohl (nTimestampFractions )) × 2e-010 × 1000 LocalFree (readfds)LocalFree (ntpBuf)closesocket (sock )freeaddrinfo (ai_list)LocalFree (hints)WSACleanup ()返回 (nlTime)
由于易语言和火山的精易模块的“取NTP服务器时间戳”都是秒戳,而没有毫秒戳,因此建议增加毫秒戳。
|
评分
-
查看全部评分
|