Coder Social home page Coder Social logo

timesync's Introduction

timesync

A simple library to synchronize time between computers. For now implemented with javascript. Check the src/js/example.js file for details.

timesync's People

Contributors

fhenus avatar

Stargazers

Johannes avatar Andrew NS Yeow avatar  avatar

Watchers

 avatar

Forkers

codenamejason

timesync's Issues

Round-trip calculation is inaccurate

Hi, and thanks for attempting a time sync library for javascript. It seems you are trying to attempt what NTP does, but of course there is no NTP client for javascript that would work in a browser because it has it's own TCP protocol.

But basically, NTP is about measuring the roundtrip time and adjusting the results accordingly, so I find this very similar.

The problem is that you are determining the offset by subtracting the entire round trip time from the server time. But if you think about it, the server took its timestamp somewhere approximately half-way along the the trip. At minimum, you should divide by 2 so you are only accounting for the return-leg of the trip.

Simple division doesn't take into account asymmetric connections though. Most users have a faster download than upload, so 2 may be too large of a divisor. Determining the right value can be very tricky.

NTP works so well because they make several samples, not just one. And both the client and the server are each adjusting sending their time to the other until consensus is reached within a particular threshold. That way, it can measure each leg of the trip separately (sort of).

Not sure if you want to do anything about this in your library or not, but I thought I would at least point it out.

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.