Skip to content

Error with example in repo #100

@sgrund14

Description

@sgrund14

Hello,

Trying to do a basic implementation here, on version 0.5.0

import { NtpTimeSync } from 'ntp-time-sync';

const defaultOptions = {
  // list of NTP time servers, optionally including a port (defaults to 123)
  servers: [
    '0.pool.ntp.org',
    '1.pool.ntp.org',
    '2.pool.ntp.org',
    '3.pool.ntp.org',
  ],

  // required amount of valid samples in order to calculate the time
  sampleCount: 8,

  // amount of time in milliseconds to wait for a single NTP response
  replyTimeout: 3000,

  // defaults as of RFC5905
  ntpDefaults: {
    port: 123,
    version: 4,
    tolerance: 15e-6,
    minPoll: 4,
    maxPoll: 17,
    maxDispersion: 16,
    minDispersion: 0.005,
    maxDistance: 1,
    maxStratum: 16,
    precision: -18,
    referenceDate: new Date('Jan 01 1900 GMT'),
  },
};

const timeSync = NtpTimeSync.getInstance(defaultOptions);

export const getNtpTime = async () => {
  try {
    const time = await timeSync.getTime();
    return time;
  } catch (error) {
    console.error('Error getting NTP time:', error);
    return null;
  }

And getNtpTime fails with this error:

Error: Connection error: Unable to get any NTP response after 3 retries

Am I doing something wrong?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions