Giter Club home page Giter Club logo

node-ntp-client's Introduction

ntp-client Build Status

Pure Javascript implementation of the NTP Client Protocol

Getting Started

Install the module with: npm install ntp-client

var ntpClient = require('ntp-client');

ntpClient.getNetworkTime("pool.ntp.org", 123, function(err, date) {
    if(err) {
        console.error(err);
        return;
    }

    console.log("Current time : ");
    console.log(date); // Mon Jul 08 2013 21:31:31 GMT+0200 (Paris, Madrid (heure d’été))
});

Contributors

License

Copyright (c) 2014 Clément Bourgeois Licensed under the MIT license.

node-ntp-client's People

Contributors

moonpyk avatar naggie avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

node-ntp-client's Issues

Unhandled error event

Presumably the error event (from DNS I think) should be passed on to the callback. It makes this library un-usable as it causes the whole app to crash out. This is with using a non-existant hostname:

$ node lib/entities/Ntp.js
{ [Error: getaddrinfo EIO] code: 'EIO', errno: 'EIO', syscall: 'getaddrinfo' }

events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: getaddrinfo EIO
    at errnoException (dns.js:37:11)
    at Object.onanswer [as oncomplete] (dns.js:124:16)

Closing closed connection ntp-client.js:80:24

If connection gets closed due to external event
error is experienced after attempt to send 'ntpData'.

Connection should be only closed if open :)

Details:

dgram.js:420
    throw new Error('Not running'); // error message from dgram_legacy.js
          ^
Error: Not running
    at Socket._healthCheck (dgram.js:420:11)
    at Socket.close (dgram.js:327:8)
    at /opt/cos-medico/new/node_modules/ntp-client/lib/ntp-client.js:80:24
    at dgram.js:297:21
    at asyncCallback (dns.js:68:16)
    at Object.onanswer [as oncomplete] (dns.js:124:7)

Instead of just averaging, you could delete the ones that are too far off from the others

I think that's how normal ntp works
Just ignore a value if it is not in the range [Q1-k(Q3-Q1),Q3+k(Q3-Q1)], where Q1 and Q3 are the 25th and 75th percentiles, k is a constant and to calculate a percentile you just do:

data_set = data_set.sort();
for (var i=0;i<data_set.length;i++){
    if (i>=data_set.length*percentile/100){
           answer = data_set[i];
           break;
    }
}

Yes, I just read all that on wikipedia

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.