There is an example how to get datetime from a ntp server in XF?
@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.
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
@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.
@AlessandroCaliaro NodaTime works with Xamarin Forms but that extension to get the NTP time does not seem to work on all platforms.
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.
Xamarin Inc., as a wholly-owned Microsoft subsidiary acting as a separate legal entity, adheres to the Microsoft Privacy Statement: Privacy & cookies