Coder Social home page Coder Social logo

ntp's People

Contributors

atrope avatar carameldunes avatar coreycole avatar knezzz avatar oonid avatar rajveermalviya avatar riccardoratta avatar safield avatar tgeorgedn 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

Watchers

 avatar  avatar  avatar  avatar

ntp's Issues

NTP.now() throws UnimplementedError on flutter web

Hey guys,

got an UnimplementedError Exception when calling NTP.now() resp. getNtpOffset() on Flutter web.
Does somebody know why this happens?

[√] Flutter (Channel stable, 2.0.2, on Microsoft Windows [Version 10.0.19041.804], locale de-DE)
[√] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
[√] Chrome - develop for the web
[√] Android Studio (version 4.1.0)
[√] VS Code (version 1.54.1)
[√] Connected device (2 available)

Exception has occurred.
"Error: UnimplementedError
at Object.throw_ [as throw] (http://localhost:52592/dart_sdk.js:5334:11)
at bind (http://localhost:52592/packages/universal_io/src/io_impl_js/sync_socket.dart.lib.js:3434:21)
at bind.next ()
at runBody (http://localhost:52592/dart_sdk.js:39052:34)
at Object._async [as async] (http://localhost:52592/dart_sdk.js:39083:7)
at Function.bind (http://localhost:52592/packages/universal_io/src/io_impl_js/sync_socket.dart.lib.js:3431:20)
at getNtpOffset (http://localhost:52592/packages/ntp/ntp.dart.lib.js:128:63)
at getNtpOffset.next ()
at http://localhost:52592/dart_sdk.js:39032:33
at _RootZone.runUnary (http://localhost:52592/dart_sdk.js:38889:58)
at _FutureListener.thenAwait.handleValue (http://localhost:52592/dart_sdk.js:33875:29)
at handleValueCallback (http://localhost:52592/dart_sdk.js:34435:49)
at Function._propagateToListeners (http://localhost:52592/dart_sdk.js:34473:17)
at _Future.new.[_completeWithValue] (http://localhost:52592/dart_sdk.js:34315:23)
at async._AsyncCallbackEntry.new.callback (http://localhost:52592/dart_sdk.js:34338:35)
at Object._microtaskLoop (http://localhost:52592/dart_sdk.js:39176:13)
at _startMicrotaskLoop (http://localhost:52592/dart_sdk.js:39182:13)
at http://localhost:52592/dart_sdk.js:34689:9"

License unknown

Hi,
first I have to say that your package works great and we are happy to have come across it!!
We from Diebold Nixdorf would like to use it in a cross-plattform app, implemented in Flutter and therefore would need a license statement.

Could you please update the file https://github.com/knezzz/ntp/blob/master/LICENSE ?
Since many Dart packages are under BSD license, does it apply to this package as well?

"TimeoutException after 0:00:05.000000: No stream event"

I am getting this error on some networks. specially when I submit the app to app store for review they rejected my app 5 times , because this plugin. It does not respond for infinite time until I have set an timeout of 5 seconds.
I am not getting any issue in my network and it worked well.
below is my code can you please check the issue and resolve it. i have tried time.google.com, time.windows.com but nothing works for app store review.

var networkDate = await NTP.now(lookUpAddress: "time.windows.com", timeout: Duration(seconds: 5));

iPhone (iOS) loses connection to device when using this package

I have installed the version ntp: 1.0.7 on my pubspec.yaml, and It works fine with android.

But as soon as I try to fetch it from my iPhone, it exits the app and it says 'Lost connection to device.'

Are there some extra instructions for iOS implementation?

need web

The gaping issue I see here is no support for flutter web.

Thanks,
Brett

IOS Issue , SocketException .

hello all. ,
i am using the ntp function , to get the real time ,
await NTP.now();

and i got this exception on ios device ,
SocketException: OS Error: Connection reset by peer, errno = 54, address = dns.google.com, port = 53945

any idea what is wrong !!

Do the APIs have some limits ?

My app could uses this API thousands of times a day.
Does time.google.com have some limits ?
What do I do to make sure it works ?

getNtpOffset fails on web with “Unsupported operation: InternetAddress.lookup”

Does ntp package support web? Web isn't explicitly mentioned in the list of supported platforms at https://pub.dev/packages/ntp, but I was under impression that the package is written in native dart and should work on all platforms.

However when I try to call getNtpOffset from a web app, it fails with “Unsupported operation: InternetAddress.lookup”.

Tested in Firefox and Chrome, in a debug build running on local host and in a release build deployed to Firebase hosting. Using Dart 2.8.1, Flutter 1.17.0-3.4.pre, ntp 1.0.6.

Disk caching

Hi, thank you for the plugin.

The plugin works fine but is too dependent on the internet.
Proposal for improvement includes adding caching of NTP time od disk, like in android and ios TrueTime plugin.

How to Handle SocketException: Failed host lookup: 'pool.ntp.org' ?

I tried your package and tested "What if the internet connection suddenly lost?"
And the result :

SocketException (SocketException: Failed host lookup: 'pool.ntp.org'
(OS Error: No address associated with hostname, errno = 7))

I want to know how to handle this problem?
Thanks a lot.

Provide documentation on how to use timeout feature

The library keep waiting infinitely in case no timeout is provided as there isn't a default value. Plus there isn't any documentation in README to actually tell end users on how to use timeout. Kindly update that.

unhandle integer max size!

if user changes his device's date more than 12 years,
the max size of the offset (which is int) will overflow and then return wrong time for NTP.getNtpOffset()

Large offset on the first getNtpOffset call

For a device that is time synchronized, the first time the getNtpOffset is called it yields a large offset (usually around 2 seconds) but on subsequent calls it will give a more realistic value (around 50 milliseconds).
This is probably due to the initialization phase (either the sockets that the plugin uses need some warming up, or the actual application starting up is taking too many resources).

This problem could be minimized if the localTime ?? DateTime.now() would be postponed to as late as possible, as well as the creation of the _NTPMessage.

NTP time & NTP Offset is not working?

I try to run the example and I get this error.
I guess this part is not working:

Error Part:
Unhandled Exception: SocketException: Failed host lookup: 'pool.ntp.org' (OS Error: No address associated with hostname, errno = 7)

Full Error:

Launching lib/main.dart on SM G935F in debug mode...
Initializing gradle...
Resolving dependencies...
Running Gradle task 'assembleDebug'...
Built build/app/outputs/apk/debug/app-debug.apk.
Installing build/app/outputs/apk/app.apk...
Syncing files to device SM G935F...
E/flutter (10544): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: SocketException: Failed host lookup: 'pool.ntp.org' (OS Error: No address associated with hostname, errno = 7)
E/flutter (10544): #0      _NativeSocket.lookup.<anonymous closure> (dart:io/runtime/binsocket_patch.dart:386:9)
E/flutter (10544): #1      _rootRunUnary (dart:async/zone.dart:1132:38)
E/flutter (10544): #2      _CustomZone.runUnary (dart:async/zone.dart:1029:19)
E/flutter (10544): #3      _FutureListener.handleValue (dart:async/future_impl.dart:126:18)
E/flutter (10544): #4      Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:639:45)
E/flutter (10544): #5      Future._propagateToListeners (dart:async/future_impl.dart:668:32)
E/flutter (10544): #6      Future._completeWithValue (dart:async/future_impl.dart:483:5)
E/flutter (10544): #7      Future._asyncComplete.<anonymous closure> (dart:async/future_impl.dart:513:7)
E/flutter (10544): #8      _rootRun (dart:async/zone.dart:1124:13)
E/flutter (10544): #9      _CustomZone.run (dart:async/zone.dart:1021:19)
E/flutter (10544): #10     _CustomZone.runGuarded (dart:async/zone.dart:923:7)
E/flutter (10544): #11     _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:963:23)
E/flutter (10544): #12     _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
E/flutter (10544): #13     _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)
E/flutter (10544): 
D/libGLESv2(10544): STS_GLApi : DTS, ODTC are not allowed for Package : com.example.ntp_time

Not getting the NTP.now()

So i am using DateTime tanzaniaLocalTimeFromDateTimeNow = await NTP.now(); in my app and it works fine sometimes, but then sometimes it doesnt give me the value. i tried keeping it in a try and catch but still i dont know what is wrong and why am i not getting the dateTime. My whole app depends on this. I am using version ntp: 1.0.7. Please help

NTP.now() throws UnimplementedError on flutter web

got an UnimplementedError Exception when calling NTP.now() resp. getNtpOffset() on Flutter web.
Does somebody know why this happens?

[√] Flutter (Channel stable, 2.0.2, on Microsoft Windows [Version 10.0.19041.804], locale de-DE)
[√] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
[√] Chrome - develop for the web
[√] Android Studio (version 4.1.0)
[√] VS Code (version 1.54.1)
[√] Connected device (2 available)

Exception has occurred.
"Error: UnimplementedError
at Object.throw_ [as throw] (http://localhost:52592/dart_sdk.js:5334:11)
at bind (http://localhost:52592/packages/universal_io/src/io_impl_js/sync_socket.dart.lib.js:3434:21)
at bind.next ()
at runBody (http://localhost:52592/dart_sdk.js:39052:34)
at Object._async [as async] (http://localhost:52592/dart_sdk.js:39083:7)
at Function.bind (http://localhost:52592/packages/universal_io/src/io_impl_js/sync_socket.dart.lib.js:3431:20)
at getNtpOffset (http://localhost:52592/packages/ntp/ntp.dart.lib.js:128:63)
at getNtpOffset.next ()
at http://localhost:52592/dart_sdk.js:39032:33
at _RootZone.runUnary (http://localhost:52592/dart_sdk.js:38889:58)
at _FutureListener.thenAwait.handleValue (http://localhost:52592/dart_sdk.js:33875:29)
at handleValueCallback (http://localhost:52592/dart_sdk.js:34435:49)
at Function._propagateToListeners (http://localhost:52592/dart_sdk.js:34473:17)
at _Future.new.[_completeWithValue] (http://localhost:52592/dart_sdk.js:34315:23)
at async._AsyncCallbackEntry.new.callback (http://localhost:52592/dart_sdk.js:34338:35)
at Object._microtaskLoop (http://localhost:52592/dart_sdk.js:39176:13)
at _startMicrotaskLoop (http://localhost:52592/dart_sdk.js:39182:13)
at http://localhost:52592/dart_sdk.js:34689:9"

In one instance NTP.now() returned (Monday, January 1, 1900 12:00:01) (-2208988798384)

Thank you for this great package :)

We have used NTP packaged in one of our app to capture start / end time for the sessions.
In one instance time captured was
(Monday, January 1, 1900 12:00:01) (-2208988798384)

I am not sure how or what is the issue. Can you please provide some details how this could have happened. I can not say I am able to recreate it, but the time captured is received from NTP.now().

time is about 1 second off between clients

I'm using NTP to synchronize audio playback across multiple mobile devices, so I need it to be quite accurate.

I notice that there's a little less than 1 second difference across the devices. Is it possible to make this more accurate?

I know that the NTP protocol requires approximately fifteen minutes to settle, but it looks like this implementation relies on a single message to an NTP server. Could that account for the difference?

This is per the ntp.org docs, if I'm reading them correctly:

When the ntpd is started and the file does not exist, the ntpd enters a special mode designed to quickly adapt to the particular system clock oscillator time and frequency error. This takes approximately 15 minutes, after which the time and frequency are set to nominal values and the ntpd enters normal mode, where the time and frequency are continuously tracked relative to the server.

How can I get my country time?

I need to get my country time, so how can I change String lookUpAddress: 'pool.ntp.org', so gets my country time? Thanks

Publish null-safety version on pub.dev

Can we have the null-safety version published on pub.dev? I'm using this package for another package and this is the only one left that hasn't been migrated to null-safety.

NTP web

When testing with the Web, it prevents it from loading, just browser goes blank.

Use simple code to validate:
timeNow() async {
DateTime _myTime;
if (kIsWeb) {
_myTime = DateTime.now();
print("Local");
} else {
_myTime = await NTP.now();
print("NTP");
}
print('My time: $_myTime');
}

PS: use translator, I speak Spanish

The method NTP.getNtpOffset() does not work

have the below code from the example folder but anytime it gets to NTP.getNtpOffset() I think it stops working cos the print statement after that does not get printed

  void _updateTime() async {
    print("before date object");
    _currentTime = DateTime.now();
print("first");
    NTP.getNtpOffset().then((int value) {
      print("If the Method works");
      setState(() {
        _ntpOffset = value;
        _ntpTime = _currentTime.add(Duration(milliseconds: _ntpOffset));

        print("ntp ofset value: $_ntpOffset  ntp time: $_ntpTime");
      });
    });
  }

Socket Exception

Hi @knezzz ,
I'm using NTP in my project, and I call getNTPOffset multiple times. Sometimes, it throws Socket Exception

I think RawDatagramSocket should be closed, but it was not.

Thank you,

Cant use NTP..

Why await NTP.now() function is not work on version 2.0.0 ?

IPv6 only broken with DoH changes

The addition of DNS over HTTPs has broken use of the plugin on IPv6 only devices (or IPv6 APNs on Android). The issue is this technique only requests 'a' records and not 'aaaa' records (in addition to only parsing ip addresses that match an IPv4 regex). Thus it only returns IPv4 address and the IPv4/IPv6 check always chooses IPv4 (and then fails when connecting to the NTP server).

Destination Timestamp is the same as Originate Timestamp in _parseData(List<int> data, DateTime time)

RFC 2030 https://tools.ietf.org/html/rfc2030 page 11-12

To calculate the roundtrip delay d and local clock offset t relative
to the server, the client sets the transmit timestamp in the request
to the time of day according to the client clock in NTP timestamp
format. The server copies this field to the originate timestamp in
the reply and sets the receive timestamp and transmit timestamp to
the time of day according to the server clock in NTP timestamp
format.
When the server reply is received, the client determines a
Destination Timestamp variable as the time of arrival according to
its clock in NTP timestamp format. The following table summarizes the
four timestamps.

Timestamp Name ID When Generated
------------------------------------------------------------
Originate Timestamp T1 time request sent by client
Receive Timestamp T2 time request received by server
Transmit Timestamp T3 time reply sent by server
Destination Timestamp T4 time reply received by client

The roundtrip delay d and local clock offset t are defined as

d = (T4 - T1) - (T2 - T3)     t = ((T2 - T1) + (T3 - T4)) / 2.

But in the NTP offset calculation the same timestamp are using as Originate Timestamp (T1) and Destination Timestamp (T4)

static Future<int> getNtpOffset({String lookUpAddress = 'pool.ntp.org', int port = 123, DateTime localTime}) async {
......
final DateTime time = localTime ?? DateTime.now();
_ntpMessage.encodeTimestamp(buffer, 40, (time.millisecondsSinceEpoch / 1000.0) + _ntpMessage.timeToUtc);
....
final int offset = _parseData(packet.data, time);
return offset;
}

static int _parseData(List<int> data, DateTime time) {
final _NTPMessage _ntpMessage = _NTPMessage(data);
final double destinationTimestamp = (time.millisecondsSinceEpoch / 1000.0) + 2208988800.0;
final double localClockOffset = ((_ntpMessage._receiveTimestamp - _ntpMessage._originateTimestamp) +
(_ntpMessage._transmitTimestamp - destinationTimestamp)) /
2;
``
return (localClockOffset * 1000).toInt();
` }`

Does It have some reasons?

Unhandled Exception: HandshakeException: Handshake error in client (OS Error: CERTIFICATE_VERIFY_FAILED: certificate is not yet valid(handshake.cc:354))

Im trying to compile the base example, but console responce me Unhandled Exception: CERTIFICATE_VERIFY_FAILED

`import 'package:ntp/ntp.dart';

Future main() async {
[
'time.google.com',
'time.facebook.com',
'time.euro.apple.com',
'pool.ntp.org',
].forEach(_checkTime);
}

Future _checkTime(String lookupAddress) async {
DateTime _myTime;
DateTime _ntpTime;

/// Or you could get NTP current (It will call DateTime.now() and add NTP offset to it)
_myTime = DateTime.now();

/// Or get NTP offset (in milliseconds) and add it yourself
final int offset = await NTP.getNtpOffset(localTime: _myTime, lookUpAddress: lookupAddress);
_ntpTime = _myTime.add(Duration(milliseconds: offset));

print('\n==== $lookupAddress ====');
print('My time: $_myTime');
print('NTP time: $_ntpTime');
print('Difference: ${_myTime.difference(_ntpTime).inMilliseconds}ms');
return;
}`

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.