WebServer, MicroFramework, C# y sin Gadgeteer

Por peticion de un amable lector…


Como punto de entrada para construir un ‘WebServer’ sin gadgeteer en C# y para microframework, os dejo la siguiente entrada :


        NetworkInterface networkInterface = NetworkInterface.GetAllNetworkInterfaces()[0];
        WebEvent myweb;
        void ProgramStarted()
        {
            Debug.Print("Program Started");
            Debug.Print("IP Address: "  + networkInterface.IPAddress.ToString());
            Debug.Print("Subnet Mask: " + networkInterface.SubnetMask.ToString());
            Debug.Print("Gateway: "     + networkInterface.GatewayAddress.ToString());
            System.Threading.Thread.Sleep(1000);
            // 
            WebServer.StartLocalServer(networkInterface.IPAddress.ToString(), 80);
            myweb = WebServer.SetupWebEvent("Hello");
            myweb.WebEventReceived +=new WebEvent.ReceivedWebEventHandler(myweb_WebEventReceived);
        }

        void myweb_WebEventReceived(string path, WebServer.HttpMethod method, Responder responder)
        {
            byte[] bte = new System.Text.UTF8Encoding().GetBytes("Hello from " + networkInterface.IPAddress.ToString() + "At " + System.DateTime.Now.ToString());
            responder.Respond(bte, "text/html");
        }
    }



Saludos,
PepLluis,

Leave a Reply

Your email address will not be published. Required fields are marked *


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>