access ntp server RRS feed

  • Question

  • User2148 posted

    Hi friends. There is an example how to get datetime from a ntp server in XF? thanks Alessandro

    Sunday, April 5, 2015 9:49 PM

All replies

  • User3466 posted

    @AlessandroCaliaro I found a really easy to use add-on for NodaTime: https://github.com/mj1856/NodaTime.NetworkClock

    Except for the fact that it mostly doesn't work with Xamarin Forms. The issue seems to be Windows Phone, which doesn't support System.Net.Sockets, which you have to have to communicate with the NTP server. iOS and Android don't seem to have an issue.

    NodaTime.NetworkClock is just a wrapper around this StackOverflow post showing how to query an NTP server.

    If you can find a Sockets PCL that allows you to communicate on all three, you might be able to write it yourself. See this forum conversation for information about that topic.

    Good luck.

    Monday, April 6, 2015 9:39 PM
  • User2148 posted

    thanks @MitchMilam . I've tried to download NodaTime package from nuget and to use it in Android, but I don't see the namespace when I try to write some code. I don't know if it can be used in Xamarin

    Tuesday, April 7, 2015 11:16 PM
  • User2148 posted

    @MitchMilam sorry, NodatimeNamespaces appears in my code, but I'm not able to have it working. I've used your stack overflow link. In Android it works. Thanks!


    Tuesday, April 7, 2015 11:32 PM
  • User3466 posted

    @AlessandroCaliaro NodaTime works with Xamarin Forms but that extension to get the NTP time does not seem to work on all platforms.

    Wednesday, April 8, 2015 1:25 PM
  • User236483 posted

    Thank you very much to do this "little" implementation @MitchMilam . I'm not familiar to use UDP, used TCP all of my life, and your IMPLEMENTED code help me very mutch. Just now I used in my application and works fine, just the line:

    ntpData = await tcs.Task.TimeoutAfter(TimeSpan.FromSeconds(3));

    I needed change to

    ntpData = await tcs.Task;

    Due a compile error here.

    I think, adding:


    Before the await call, result in same thing. I will test with 10 ms answer timeout to see what happens because the actual proccess are leaving about 200ms.

    Wednesday, July 20, 2016 7:40 PM