Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Problem getting time via NTP (Socket Exception)

NTP Socket Time Server Netduino Plus 2 Socket Exception

Best Answer JerseyTechGuy, 15 March 2013 - 03:57 PM

Ok, I may have figured it out and it was probably my main router.  I had to go into the router and look at the DNS servers on the WAN tab:

Posted Image

 

Then I copied then to the DHCP settings tab and used them as static DNS 1,2,3.  After rebooting the Netduino Plus 2 it started getting the time fine.

Posted Image

Go to the full post


  • Please log in to reply
3 replies to this topic

#1 JerseyTechGuy

JerseyTechGuy

    Advanced Member

  • Members
  • PipPipPip
  • 870 posts

Posted 15 March 2013 - 12:56 PM

Hey all,

 

Having an issue with an NTP time server class.  I am not a networking expert so perhaps someone with networking experience may be able to take a guess at the issue.  I am not confident that the problem is not the Netduino Plus 2 although everything on the Netduino seems fine.

 

So, first I am loading the Network settings from the SD card.  I have ensured and double checked that I have a valid IP address and it is not in conflict.  I also have a proper subnet Mask, Gateway and the Primary and Secondary DNS servers are in deed correctly pulled and match those from my Cable model.  So it seems that DHCP on the Netduino is working correctly.

 

I am getting two failure points.  First it fails on the DNS lookup of the time server.  The time server I am using in this case is pool.ntp.org (I've also tried others).  The codeline is as follows:

IPAddress[] address = Dns.GetHostEntry("pool.ntp.org").AddressList;

When it runs it sits on this line for x seconds then throws an exception of "Exception was thrown: System.Net.Sockets.SocketException".

 

I have a try/catch around it setting a backup IP address for the address if GetHostEntry fails.  Then, since either way we'll have an IP Address. I create the Socket and all looks good however it seems to time out.  The code I am using uses socket.Poll after using the socket.SendTo to send the request  Code follows:

if (s.Poll(30 * 1000 * 1000, SelectMode.SelectRead))

The 30 * 1000 * 1000 is the number of microseconds to wait (timeout) so this is 30 seconds.  They recommend 10 but I have it a little longer.  It basically sits for the 30 seconds then s.Poll returns "false" thus skipping all the time extraction code and finally closing the socket.

 

I have checked everything I can think of and I am unsure why it fails on the DNS lookup as well as times out on the polling.

 

Does anyone have NTP successfully working on the Netduino Plus 2?  Has anyone experienced such an issue and found a solution for it?



#2 JerseyTechGuy

JerseyTechGuy

    Advanced Member

  • Members
  • PipPipPip
  • 870 posts

Posted 15 March 2013 - 03:57 PM   Best Answer

Ok, I may have figured it out and it was probably my main router.  I had to go into the router and look at the DNS servers on the WAN tab:

Posted Image

 

Then I copied then to the DHCP settings tab and used them as static DNS 1,2,3.  After rebooting the Netduino Plus 2 it started getting the time fine.

Posted Image



#3 emg

emg

    Advanced Member

  • Members
  • PipPipPip
  • 129 posts

Posted 15 March 2013 - 09:02 PM

I don't get it, why do you have 2x the same DNS IP for primary/secondary? IFAIK, this just means it takes twice as long to fail over to the next DNS server if 24.229.54.212 is down or slow to respond.

 

I've found Google DNS 8.8.8.8 and 8.8.4.4 to be good and it does not lock you to your ISP DNS. They seem quick and don't block anything (ISP's in the UK like to block PirateBay et al).

 

In general, split your troubleshooting into routing and name resolution. If you can ping or connect to ntp via IP address then you've isolated the problem to DNS. Also, check your ISP's current DNS settings as they can change over time (esp if you have been with them for years - this happened to me). Some ISP's provide different DNS servers for each type of service they offer, home, business, etc. The order is sometimes also important. The Primary DNS is usually the fastest over the Secondary but again it depends on ISP.



#4 JerseyTechGuy

JerseyTechGuy

    Advanced Member

  • Members
  • PipPipPip
  • 870 posts

Posted 16 March 2013 - 03:49 PM

I don't get it, why do you have 2x the same DNS IP for primary/secondary? IFAIK, this just means it takes twice as long to fail over to the next DNS server if 24.229.54.212 is down or slow to respond.

 

I've found Google DNS 8.8.8.8 and 8.8.4.4 to be good and it does not lock you to your ISP DNS. They seem quick and don't block anything (ISP's in the UK like to block PirateBay et al).

 

In general, split your troubleshooting into routing and name resolution. If you can ping or connect to ntp via IP address then you've isolated the problem to DNS. Also, check your ISP's current DNS settings as they can change over time (esp if you have been with them for years - this happened to me). Some ISP's provide different DNS servers for each type of service they offer, home, business, etc. The order is sometimes also important. The Primary DNS is usually the fastest over the Secondary but again it depends on ISP.

 

This is the way the DHCP settings automatically configured from the Cable Modem.  Not sure why the 2nd failover matches the first.  We live up in the sticks in Northern New Jersey.  "Bob's Cable Service" doesn't really have their stuff together so I'm not surprised.

 

Since Pandora's Box will not be running on anyone's network fulltime but rather only when they are setting it up through my windows application or when they are in need of updating the time/date. I'm not too worried about using Google's DNS services.  I simply needed to determine that the issue was indeed a router configuration issue and correct it so I can add this to the end user documentation and eventual Wiki on ScareTronix website.







Also tagged with one or more of these keywords: NTP, Socket, Time Server, Netduino Plus 2, Socket Exception

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.