Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android and iOS errors #9

Closed
zoanthal opened this issue Mar 15, 2018 · 3 comments
Closed

Android and iOS errors #9

zoanthal opened this issue Mar 15, 2018 · 3 comments

Comments

@zoanthal
Copy link

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;
        }
    }
@Yortw
Copy link
Owner

Yortw commented Mar 21, 2018

Hi,

Sorry, have been busy this week. The iOS problem sounds similar to an issue that occurred on Android initially, but I didn't think applied to iOS. Unfortunately I don't have access to any Apple equipment this week to investigate.

Could you please try the same code, but initialising the NtpClient class with the IP address of the server rather than name? i.e

    NtpClient client = new NtpClient("64.99.80.121")

and let me know if that works or not?

Thanks.

@zoanthal
Copy link
Author

zoanthal commented Mar 22, 2018 via email

@Yortw
Copy link
Owner

Yortw commented Mar 22, 2018

That's ok.
PS: I wasn't suggesting this as a long term solution, just to see if it worked for you, as that would prove if it is the same issue I already have a solution for on Android.

@Yortw Yortw closed this as completed in fa53ded Apr 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants