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

NtpNetworkException when awaiting RequestTimeAsync() #5

Closed
adolgov opened this issue Jan 21, 2017 · 6 comments
Closed

NtpNetworkException when awaiting RequestTimeAsync() #5

adolgov opened this issue Jan 21, 2017 · 6 comments

Comments

@adolgov
Copy link

adolgov commented Jan 21, 2017

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

@adolgov
Copy link
Author

adolgov commented Jan 21, 2017

Same behavior (same exception type/message in ErrorOccurred event) when using the non-async calls

var client = new NtpClient(KnownNtpServers.NorthAmericaOrg);

client.TimeReceived += Client_TimeReceived;
client.ErrorOccurred += Client_ErrorOccurred;
client.BeginRequestTime();

@Yortw
Copy link
Owner

Yortw commented Jan 24, 2017

Sorry for the delayed reply, I have been away and was not in a position to do development or check GitHub.

I'm also sorry this isn't working for you. It appears to just be broken. I swear I tested it on Android before publishing, but it doesn't work now and it doesn't look like it ever did so I don't know what happened.

The basic problem is that Xamarin Android purports to support all the same socket API's as the desktop framework/iOS etc. but at least one of them throws a NotImplementedException and doesn't really work. Specifically calling System.Net.Sockets.Socket.Connect and passing a DnsEndPoint instance throws an exception from the EndPoint base class used by DnsEndPoint. I haven't found any way around this. I'm not sure what the point of DnsEndPoint is in Xamarin Android if you can't pass it to a socket.

However, I have found the same code works with an IpEndPoint, so it may be possible to do a manual DNS resolution of the server name to IP, then pass the IP to the socket. However I haven't had time yet to confirm this, and because it's (probably) (marginally) less efficient I'd prefer to only do it on Android, so it will need either a new implementation or some conditional compilation logic in the shared code file.

I'll let you know if/when I've managed to find a solution.

Thanks for reporting the problem.

@adolgov
Copy link
Author

adolgov commented Jan 24, 2017

Thank you for your response.

Let me know if I can help test a potential solution.

@Yortw
Copy link
Owner

Yortw commented Jan 25, 2017

Hi,

I've published a beta package (https://www.nuget.org/packages/Yort.Ntp.Portable/1.0.10-beta) to Nuget . Make sure you turn on the 'pre-release' option in VS to see the new version.

I've tested it on a Samsung Galaxy S5 on Android 6.0.1 and it seems to work.

Please try that package and let me know if it works for you.

Thanks.

@adolgov
Copy link
Author

adolgov commented Jan 25, 2017

The new version works. Thanks for the quick fix!

@adolgov adolgov closed this as completed Jan 25, 2017
@Yortw
Copy link
Owner

Yortw commented Jan 25, 2017

No problem. Thanks for reporting it.

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