Abdi Getachew
Abdi Getachew

Reputation: 75

Set up web server connected via Ethernet. IPaddress gives 0.0.0.0

This is the code I got from a book called Getting started with .net gadgeeter. Whenever I print the Ip address it's 0.0.0.0 even though I can see that it's connected to my network and has an IP address. What am I doing wrong?

namespace HelloWebServer
{
    public partial class Program
    {
        GT.Networking.WebEvent sayHello;

    void ProgramStarted()
    {
        ethernet.UseDHCP();
        ethernet.NetworkUp += new GTM.Module.NetworkModule.NetworkEventHandler(ethernet_NetworkUp);
        ethernet.NetworkDown += new GTM.Module.NetworkModule.NetworkEventHandler(ethernet_NetworkDown);
        led.TurnBlue();
    }


    void ethernet_NetworkUp(GTM.Module.NetworkModule sender, GTM.Module.NetworkModule.NetworkState state)
    {
        led.TurnGreen();
        string ipAddress = ethernet.NetworkSettings.IPAddress;
        Debug.print("ip address"+ipAddress);
        WebServer.StartLocalServer(ipAddress, 80);
        sayHello = WebServer.SetupWebEvent("hello");
        sayHello.WebEventReceived += new WebEvent.ReceivedWebEventHandler(sayHello_WebEventReceived);
    }

    void sayHello_WebEventReceived(string path, WebServer.HttpMethod method, Responder responder)
    {
        string content = "<html><body><h1>Hello World!!</h1></body></html>";
        byte[] bytes = new System.Text.UTF8Encoding().GetBytes(content);
        responder.Respond(bytes, "text/html");
    }


    void ethernet_NetworkDown(GTM.Module.NetworkModule sender, GTM.Module.NetworkModule.NetworkState state)
    {
        led.TurnRed();
    }


}

}

Upvotes: 1

Views: 60

Answers (1)

Wolfgang Feneberg
Wolfgang Feneberg

Reputation: 236

i think there was(is) a Bug in the netmf Library and DHCP not work correct. Please use static IP-Address.

ethernet.UseStaticIP(
                "192.168.1.222",
                "255.255.254.0",
                "192.168.1.1");

Upvotes: 1

Related Questions