Giter Club home page Giter Club logo

yort.ntp's People

Contributors

kvpt avatar mill1000 avatar sundhaug92 avatar yortw 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

Watchers

 avatar  avatar  avatar  avatar  avatar

yort.ntp's Issues

NtpNetworkException when awaiting RequestTimeAsync()

I'm trying to run a basic ntp time fetch in Xamarin.Android.

var client = new NtpClient();
var dt = await client.RequestTimeAsync();

While it's a simple example, I'm getting a NtpNetworkException with message This method is not implemented by this class.

The inner exception stack trace mentions:
at System.Net.EndPoint.Serialize () [0x00000] in /Users/builder/data/lanes/4009/72366f70/source/mo…

Any suggestions as to what I can try?
Version is latest from NuGet 1.0.9

Time issue

Hi,

I use this library in an application (Xamarin) deployed on mobile devices, which may have network connection reliability issues.

It works great 99.99%, but sometime in my api, I receive call from the app with invalid dates.
For example :

  • 01/01/1900 01:05:12
  • 01/01/1900 01:04:55
  • 01/01/1900 00:32:17

I found in the code here that the default time is 01/01/1900, so I suspect an incomplete buffer to cause this issue.

My question is how to handle this case ?

A/ An exception must be raised by the library
B/ Date must be verified by user code

Problem with Raspberry Pi

I've used this Code with Mono on a Raspberry Pi but it doesn't work. The same Code works with Visual Studio on Windows. On Windows i get "NTP OK" and on the Raspberry I get "NTP ERORR".

    public static void CheckTimeOK()
    {
        var client = new Yort.Ntp.NtpClient("130.149.17.21");    
        client.TimeReceived += Client_TimeReceived;
        client.ErrorOccurred += Client_ErrorOccurred;
        client.BeginRequestTime();
    }

    public static void Client_ErrorOccurred(object sender, NtpNetworkErrorEventArgs e)
    {
        Console.WriteLine("NTP ERROR");
    }

    public static void Client_TimeReceived(object sender, NtpTimeReceivedEventArgs e)
    {
        System.Diagnostics.Debug.WriteLine(e.CurrentTime);
        Console.WriteLine("NTP ok");
    }

Socket unsubscription to OnMessageReceived throws Exception "A method was called at an unexpected time."

Hi,
on Windows Phone 8.1 (RT) class NtpClient(NtpClientWinRTSockets.cs) throws Exception with description "A method was called at an unexpected time.".

I found this post on SO

http://stackoverflow.com/questions/16147904/how-to-unsubscribe-from-datagramsocket-messagereceived-event

where the guideline it's to just don't subscribe from the event, the .Dispose() will do the job. I suggest to follow this approach, cause it's working for me. I commented

socket.MessageReceived -= this.Socket_Completed_Receive;

in file NtpClientWinRTSockets.cs.

Best regards

System.Net.EndPoint.Serialize throws System.NotImplementedException on Mono Linux

Yort uses EndPoint as a parameter to Socket.Connect, the Serialize method is not implemented in Mono Linux which results in the exception below. In order to be compatible with Mono Linux/Android etc IPEndPoint could be used instead.

try {
 var client = new NtpClient(_ntpServer);
 Task < RequestTimeResult > task = client.RequestTimeAsync();
 task.Wait();
 var currentTime = task.Result;
 return currentTime.NtpTime.CreateUnixTimeStamp();
} catch (Exception exception) {
 _loggingService.Error($ "Error while syncing time with NTP: {exception}");
 throw;
}

Yort.Ntp.NtpNetworkException: This method is not implemented by this class. ---> System.NotImplementedException: This method is not implemented by this class.
at System.Net.EndPoint.Serialize () [0x00005] in <41574d2cca96494f8f406b75a489d430>:0
at System.Net.Sockets.Socket.Connect (System.Net.EndPoint remoteEP) [0x00070] in <41574d2cca96494f8f406b75a489d430>:0
at Yort.Ntp.NtpClient.SendTimeRequest () [0x00092] in :0
--- End of inner exception stack trace ---
--- End of inner exception stack trace ---
at System.Threading.Tasks.Task.ThrowIfExceptional (System.Boolean includeTaskCanceledExceptions) [0x00011] in :0
at System.Threading.Tasks.Task.Wait (System.Int32 millisecondsTimeout, System.Threading.CancellationToken cancellationToken) [0x00043] in :0
at System.Threading.Tasks.Task.Wait () [0x00000] in :0
at Services.NtpSyncService.GetTime () [0x000aa] in <461fb7cf28f04e90bf48c2b50181c3b6>:0
---> (Inner Exception #0) Yort.Ntp.NtpNetworkException: This method is not implemented by this class. ---> System.NotImplementedException: This method is not implemented by this class.
at System.Net.EndPoint.Serialize () [0x00005] in <41574d2cca96494f8f406b75a489d430>:0
at System.Net.Sockets.Socket.Connect (System.Net.EndPoint remoteEP) [0x00070] in <41574d2cca96494f8f406b75a489d430>:0
at Yort.Ntp.NtpClient.SendTimeRequest () [0x00092] in :0
--- End of inner exception stack trace ---<---

Something not right with nuget package?

Hi,

I was trying to use the library in another portable library, but if I try and add it from nuget it gives an error...

Could not install package 'Yort.Ntp.Portable 1.0.2'. You are trying to install this package into a project that targets '.NETPortable,Version=v4.0,Profile=Profile158', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.

However, I grabbed the source, recompiled and manually added the reference and it seems to be fine.

I don't work with portable stuff much, so it's quite possibly my mistake, but thought I'd raise it?

Thanks,
Adam.

Specific assembly exception

Hi, when I invoke the BeginRequestTime method of an NTPClient object I get this exception:

"This assembly should never be loaded at runtime, and should only be referenced from other portable class libraries. Please ensure your application references a platform specific assembly."

Android and iOS errors

Works OK in Android. I frequently/occasionally get this error:

[0:] Yort.Ntp.NtpNetworkException: OperationAborted
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in :0
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0003e] in :0
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in :0
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in :0
at System.Runtime.CompilerServices.TaskAwaiter`1[TResult].GetResult () [0x00000] in :0
at DMRxForPrimaryCare.SA_AsyncCalls+d__11.MoveNext () [0x000a2] in C:\Xamarin\DMRxForPrimaryCare\DMRxForPrimaryCare\DMRxForPrimaryCare\SA_AsyncCalls.cs:379

On iOS, no luck. Stacktrace:

Yort.Ntp.NtpNetworkException: This method is not implemented by this class. ---> System.NotImplementedException: This method is not implemented by this class.
at System.Net.EndPoint.Serialize () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.8.0.20/src/Xamarin.iOS/mcs/class/referencesource/System/net/System/Net/EndPoint.cs:40
at System.Net.Sockets.Socket.Connect (System.Net.EndPoint remoteEP) [0x00070] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.8.0.20/src/Xamarin.iOS/mcs/class/System/System.Net.Sockets/Socket.cs:868
at Yort.Ntp.NtpClient.SendTimeRequest () [0x00092] in :0

Implementation:

    public static DateTime localLastNTPCheckUTC = DateTime.UtcNow;
    public static bool havecheckedNTP = false;
    public static bool failedNTP = false;
    public static DateTime lastNTP = DateTime.UtcNow;

    public static async Task<DateTime> GetAtomicTimeJSON()
    {
        try
        {
            if (havecheckedNTP)
            {
                TimeSpan t = DateTime.UtcNow - localLastNTPCheckUTC;
                if (t.TotalMilliseconds <= 4000)
                {
                    return lastNTP.AddMilliseconds(t.TotalMilliseconds);
                }
            }

            NtpClient client = new NtpClient(KnownNtpServers.PoolOrg);
            DateTime currentTime = await client.RequestTimeAsync();
            //Debug.WriteLine("NTP success: "+currentTime.ToString());
            havecheckedNTP = true;
            failedNTP = false;
            lastNTP = currentTime;
            return currentTime;
        }
        catch (Exception ex)
        {
            havecheckedNTP = false;
            failedNTP = true;
            Debug.WriteLine("NTP failure");
            Debug.WriteLine(ex.ToString());
            return System.DateTime.UtcNow;
        }
    }

Get a problem trying to build .net core

Just gone back to some stuff I was working on, to update to RC2 (core stuff). I updated all the packages and things, including this one to 1.0.7, and now my build... he not happy.

I'm fiddling with the project.json/.lock to try and work out why it's doing this, but I thought I'd let you know in the mean time, in case you have the magic answer :)

C:\TFSDefault\PayteqCore\src\Payteq.Core\Services\Licensing\Validation\LicenseValidationExtensions.cs(65,13): error CS0433: The type 'NtpClient' exists in both 'Yort.Ntp.Net45, Version=1.0.0.6, Culture=neutral, PublicKeyToken=null' and 'Yort.Ntp, Version=1.0.0.7, Culture=neutral, PublicKeyToken=null'
C:\TFSDefault\PayteqCore\src\Payteq.Core\Services\Licensing\Validation\LicenseValidationExtensions.cs(65,39): error CS0433: The type 'NtpClient' exists in both 'Yort.Ntp.Net45, Version=1.0.0.6, Culture=neutral, PublicKeyToken=null' and 'Yort.Ntp, Version=1.0.0.7, Culture=neutral, PublicKeyToken=null'

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.