This project is read-only.

Fix IPv4 Configuration

Aug 5, 2012 at 3:26 PM

Hello Markus!

               I posted in Netduino+ forum my doubt but no body replay, so, I try here now. Have some way to fix the IPv4 configuration? I have many troubles because when I start

 Server WebServer = new Server(PinManagement.OnboardLED, 80, false);
constructor it's does not work. In yours default configuration
 Server WebServer = new Server(PinManagement.OnboardLED)

             The IP come from default value of "a type DHCP" (based on your PC experiences IP's), I made many tests to understand that. My network it's made to fix IP - my DHCP generate IP in other subnetwork to cause troubles when some try to break my wireless password and use my internet ( :) ).

            I made a little solution for this problem based on NetworkInterface documentation:

        /// <summary>
        /// Creates an instance running in a seperate thread
        /// </summary>
        /// <param name="ledPort">OutputPort to indentify</param>
        /// <param name="portNumber">The port to listen</param>
        /// <param name="DhcpEnable"></param>
        /// <param name="ipAddress">IP</param>
        /// <param name="subnetMask">Mask</param>
        /// <param name="gatewayAddress">GateWay</param>
        public Server(OutputPort ledPort, int portNumber = 80, bool DhcpEnable = false,
                      string ipAddress = "", string subnetMask = "", string gatewayAddress = "")
        {
            var interf = NetworkInterface.GetAllNetworkInterfaces()[0];

            if (DhcpEnable)
            {
                interf.EnableDhcp();
                interf.RenewDhcpLease();
            }
            else
            {
                //New to fix 
                interf.EnableStaticIP(ipAddress, subnetMask , gatewayAddress );

            }

            //Debug.Print("Webserver is running on " + interf.IPAddress + " /// DHCP: " + interf.IsDhcpEnabled);

            this._PortNumber = portNumber;
            _OnboardLed = ledPort;
            ResponseListInitialize();

            _ListeningSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            _ListeningSocket.Bind(new IPEndPoint(IPAddress.Any, portNumber));
            _ListeningSocket.Listen(4);

            var webserverThread = new Thread(WaitingForRequest);
            webserverThread.Start();
        }

I would like to know if have other way to insert the IP address and fix it without modification in your code.

Thanks,

               Victor

Nov 23, 2012 at 10:15 AM

Hello Victor,

Sorry, I didn't work on NeonMika.Webserver the last month because of many personal things to do.
I thank you for your piece of code. I included it, so everbody can now use static IPs without configurating it on Windows :)

Greets, Markus