Ntp客户端
function parseMsg (buffer) {
if (buffer.length !== 48) return;
const pkt = {},
now = new Date().getTime();
pkt.leapIndicator = buffer[0] >> 6;
pkt.version = (buffer[0] & 0x38) >> 3;
pkt.mode = buffer[0] & 0x7;
pkt.stratum = buffer[1];
pkt.interval = Math.pow(2, buffer[2]);
pkt.precision = Math.pow(2, buffer[3]) * 1000;
pkt.rootDelay = 1000 * ((256 * (256 * (256 * buffer[4] + buffer[5]) + buffer[6]) + buffer[7]) / 0x10000);
pkt.rootDispersion = ((buffer[8] << 8) + buffer[9] + ((buffer[10] << 8) + buffer[11]) / Math.pow(2, 16)) * 1000;
pkt.referenceId = pkt.stratum < 2 ? String.fromCharCode(buffer[12]) + String.fromCharCode(buffer[13]) + String.fromCharCode(buffer[14]) + String.fromCharCode(buffer[15]) : pkt.stratum < 16 ? `${buffer[12]}.${buffer[13]}.${buffer[14]}.${buffer[15]}` : '';
pkt.referenceTimestamp = toMsecs(buffer, 16);
pkt.originateTimestamp = toMsecs(buffer, 24);
pkt.receiveTimestamp = toMsecs(buffer, 32);
pkt.transmitTimestamp = toMsecs(buffer, 40);
pkt.time = pkt.originateTimestamp;
pkt.delay = ((now - pkt.originateTimestamp) - (pkt.transmitTimestamp - pkt.receiveTimestamp)).toFixed(3) / 1;
pkt.offset = (((pkt.receiveTimestamp - pkt.originateTimestamp) + (pkt.transmitTimestamp - now)) / 2).toFixed(3) / 1;
return pkt;
}
function toMsecs(buffer, offset) {
let seconds = 0, fraction = 0;
for (let i = 0; i < 4; i++) {
seconds = (seconds * 256) + buffer[offset + i];
}
for (let i = 4; i < 8; i++) {
fraction = (fraction * 256) + buffer[offset + i];
}
return (seconds - 2208988800 + (fraction / Math.pow(2, 32))) * 1000;
}
Ntp客户端的更多相关文章
- Centos7安装搭建NTP服务器和NTP客户端同步时间
NTP简介: NTP是网络时间协议(Network Time Protocol),它是用来同步网络中各个计算机的时间的协议. 在计算机的世界里,时间非常地重要 例如:对于火箭发射这种科研活动,对时间的 ...
- 003.NTP客户端配置
一 NTP客户端同步方式 ntpdate定时任务同步 ntp服务同步 二 ntpdate定时任务同步 2.1 安装ntp软件 [root@client ~]# yum -y install ntp # ...
- NTP客户端的设置
LINUX做为客户端自动同步时间 如果想定时进行时间校准,可以使用crond服务来定时执行. 编辑 /etc/crontab 文件 加入下面一行: 30 8 * * * root /usr/sbi ...
- linux服务器ntp客户端配置【转】
转自:https://www.cnblogs.com/kerrycode/archive/2015/08/20/4744804.html 在Linux系统中,为了避免主机时间因为在长时间运行下所导致的 ...
- 安装ntp服务,并设置ntp客户端
1.yum安装ntp [root@localhost ~]# yum install ntp 2.修改配置文件 配置文件在/etc/ntp.conf
- C实现一个NTP客户端,可以从指定IP的NTP服务器获取时间戳
参考::https://blog.csdn.net/dosthing/article/details/81588219 下面的代码测试通过 头文件 #include <sys/types.h&g ...
- H3C/华为交换机配置NTP客户端
H3C clock timezone UTC add ntp-service unicast-server 1.1.1.1 //ntp服务器地址 clock protocol ntp ntp-serv ...
- ntp服务器搭建与客户端设置
服务器对时间要求非常严格,linux服务器文件的生成,日志,以及数据库的连接都是根据时间的逻辑 进行任务处理,如果时间不同步,那么,处理的任务,以及出问题的分析日志,时间不对,很难分析 直接更改lin ...
- 华为交换机配置NTP服务端/客户端
作者:邓聪聪 配置设备作为NTP服务器 单播客户端/服务器模式 # 配置NTP主时钟,层数为2. <HUAWEI> system-view [HUAWEI] ntp refclock-ma ...
随机推荐
- debian 9 更换源 使用国内源 配置方法
配置前请先参考: https://wiki.debian.org/SourcesList https://www.debian.org/mirror/list https://mirrors.tuna ...
- sql复制表结构,复制表内容语句
sql复制表结构,复制表内容语句 select * into b from a where 1<>1 select top 0 * into b from a insert into a ...
- 微信第三方登录测试时报Scope参数错误或没有Scope权限解决方法
一 报错信息: 二 出现原因分析: 出现这种错误网上查出现有的原因是: 1. 订阅号没有相关的权限 2. 账号没有认证,没有相关的权限 那么这里遇到问题两种都不是.开发账号是 服务号,而且也是认证号. ...
- 完全卸载memcached的方法(CentOS)
前阵子给服务器装了个memcached,4G的内存,想给网站提提速,实际上不但没有明显效果,反倒耗费内存,看着碍眼,于是想卸载,网上各种搜索+自己实践,搞出一个傻瓜方案来: 1.首先查找你的memca ...
- python-字符串-技巧
1.删除字符串末尾空白:rstrip函数 test1 = "This is a test " print(test1.rstrip()) 但是这种删除只是暂时的,如果想永久删除,则 ...
- element onclick 动态创建元素并绑定onclick事件
<html> <head> <meta charset="UTF-8"> <title>b</title> <sc ...
- 编写高质量代码改善C#程序的157个建议——建议147:重构多个相关属性为一个类
建议147:重构多个相关属性为一个类 若存在多个相关属性,就应该考虑是否将其重构为一个类.查看如下类: class Person { public string Address { get; set; ...
- 哇,两门学考都是A(〃'▽'〃)
看来只要拼命去搞,两个月也是可以搞出来的啊~
- 解决word2013老是打开未响应情况
问题:自己装了word2013时,每次打开word或者工作时,老是出现一个圈圈,提示未反应,是否关闭程序这样的提示: 解决方法:文件->选项->高级->显示->禁用硬件加速,将 ...
- linux 常见命令--系统信息部分
head -n 1 /etc/issue #查看操作系统 cat /etc/redhat-release #查看linux系统版本 cat /proc/meminfo |grep MemTot ...