Netduino Plus DHCP

Device networking fun and games

Posted by Tom Cole on September 6, 2012

Over the last week I’ve been playing around with a Netduino Plus for a little project I’ve been planning for a while. It’s a great little device and really easy to get started with.

The first project I tried was to create a little webserver and I found a great “hello world” example here:

The tutorial is pretty thorough but I ran into an interesting problem when outputting the assigned IP address out to the debug console while the device was attached to my router via ethernet via the code below:

socket = new Socket(AddressFamily.InterNetwork,SocketType.Stream, ProtocolType.Tcp);
socket.Bind(new IPEndPoint(IPAddress.Any, 80));

I found that every time I started debugging it always output the IP: This is not on my router’s subnet (

After a bit of digging I found that is in fact the Netduino’s default IP address and that by being output at this point the most likely issue was that the router hadn’t assigned an IP to the device. This can indicate a network configuration issue but in my case it was because it was taking a while to assign an IP (through DHCP) to the device.

A quick rough tweak to the code fixed the issue by adding a while loop to wait for the IP to be assigned before starting listening.

socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
socket.Bind(new IPEndPoint(IPAddress.Any, 80));
string address =  Microsoft.SPOT.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()[0].IPAddress;
while (address == "")
    address =  Microsoft.SPOT.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()[0].IPAddress;

Hope this saves other people time if they run into the same issue.