Giter Club home page Giter Club logo

ntp_client's Introduction

ntp_client

使用NTP协议获取网络时间戳,提供的 C/C++ 源码支持 Windows 和 Linux(CentOS) 两大平台。

Winodws 平台上编译与测试

在 VC 的命令行环境下,使用 nmake /f Makefile.mk 命令进行编译,输出的测试程序为 ntp_cli_test.exe ,执行该程序,即可看到测试结果。

Linux 平台上编译与测试

# make
# ./ntp_cli_test

依次执行上面的命令,即可看到测试结果。

源码说明

  • VxDType.h: 定义通用数据类型的头文件。
  • VxNtpHelper.h:使用NTP协议获取网络时间戳所提供的 API 与相关数据定义的头文件。
  • VxNtpHelper.cpp:VxNtpHelper.h中提供的操 API 实现源码文件。
  • main.cpp:接口调用流程(测试程序)。

测试程序的输出样例信息如下:

  1.cn.pool.ntp.org -> 193.228.143.22

        time1 : 2018-11-16_18-43-43.126
        time2 : 2018-11-16_18-43-43.245
        time3 : 2018-11-16_18-43-43.245
        time4 : 2018-11-16_18-43-43.419
        timev : 2018-11-16_18-43-43.391
        timec : 2018-11-16_18-43-43.419
        1.cn.pool.ntp.org : 2018-11-16_18-43-43.391
  • time1 : 客户端 发送一个NTP报文给 服务端,该报文带有它离开 客户端 时的时间戳 (T1)。
  • time2 : 当此NTP报文到达 服务端 时,服务端 加上自己的时间戳 (T2)。
  • time3 : 当此NTP报文离开 服务端 时,服务端 再加上自己的时间戳 (T3)。
  • time4 : 当 客户端 接收到该应答报文时,客户端 的本地时间戳 (T4)。
  • timev : 同步到的时间戳 T = T4 + ((T2 - T1) + (T3 - T4)) / 2;
  • timec : 系统当前的时间。

具体项目中的应用,参看 main.cpp 中的调用流程。

ntp_client's People

Contributors

gaaagaa avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.