Library problem: GHIElectronics.NETMF.W5100.Http

Hi,
using GHIElectronics.NETMF.W5100.Http library but i have no mamed problem. used code and debug output is bellow. code is do nothing and waiting infinite when context.Response.Headers.Count.ToString(); called. Whats wrong?


namespace OMR.MyHttpServer
{
    using GHIElectronics.NETMF.Net;
    using GHIElectronics.NETMF.Net.NetworkInformation;
    using Microsoft.SPOT;

    public class Program
    {
        public static void Main()
        {
            Debug.Print("Network interface initializing...");
            InitializeIp();

            StartHttpServer(80);
        }

        private static void StartHttpServer(int port)
        {
            var hl = new HttpListener("http", port);
            hl.Start();

            HttpListenerContext context = null;

            while (true)
            {
                context = hl.GetContext();
                Debug.Print("on request");

                try
                {
                    string str = context.Response.Headers.Count.ToString();

                    Debug.Print(str);
                }
                catch (System.Exception ex)
                {
                    Debug.Print("Exception: " + ex.ToString());
                }
                finally
                {
                    Debug.Print("finally");
                }
            }
        }

        private static void InitializeIp()
        {
            byte[] ip = { 192, 168, 2, 107 };
            byte[] subnet = { 255, 255, 255, 0 };
            byte[] gateway = { 192, 168, 2, 1 };
            byte[] mac = { 0x00, 0x26, 0x1C, 0x7B, 0x28, 0xE8 };

            NetworkInterface.EnableStaticIP(ip, subnet, gateway, mac);
            NetworkInterface.EnableStaticDns(new byte[] { 192, 168, 0, 1 });
        }

    }
}


...
'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:\Program Files\GHI Electronics\GHI NETMF v4.1 SDK\Assemblies\le\FEZPanda_II_GHIElectronics.NETMF.FEZ.dll'
The thread '<No Name>' (0x2) has exited with code 0 (0x0).
Network interface initializing...
on request

Don’t reinvent the wheel, grab the HTTP Server from http://code.tinyclr.com/project/426/fez-connect-web-server/.

The problem to me looks like you never call WIZnet_W5100.Enable which I think is the problem. You need to tell the W5100 code how to talk to the device !

@ omerfarukz

Do you see the output of any of these print statements?


Debug.Print("on request");
Debug.Print(str);
Debug.Print("finally");

I saw On Request shown in the above post, but neither of the others

Oh, yes… now I see it :-[

One more question:
Why are you checking the count of “response” headers before you send anything back to the client? It would make more sense to check “request” headers.

Yeah, this code is okay. Thanks. i forgot to enable wiznet.


using GHIElectronics.NETMF.FEZ;
using GHIElectronics.NETMF.Net;
using GHIElectronics.NETMF.Net.NetworkInformation;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;

namespace MFConsoleApplication2
{
    public class Program
    {
        public static void Main()
        {
            InitNetworkInterface();

            var hl = new HttpListener("http", 8080);
            hl.Start();

            while (true)
            {
                var c = hl.GetContext();

                Debug.Print(c.Request.Headers.Count.ToString());
            }
        }

        private static void InitNetworkInterface()
        {
            byte[] ip = { 192, 168, 2, 106 };
            byte[] subnet = { 255, 255, 255, 0 };
            byte[] gateway = { 192, 168, 2, 1 };
            byte[] mac = { 0x00, 0x26, 0x1C, 0x7B, 0x29, 0xE8 };

            WIZnet_W5100.Enable(SPI.SPI_module.SPI1, (Cpu.Pin)FEZ_Pin.Digital.Di10, (Cpu.Pin)FEZ_Pin.Digital.Di7, true);

            NetworkInterface.EnableStaticIP(ip, subnet, gateway, mac);
            NetworkInterface.EnableStaticDns(new byte[] { 192, 168, 2, 1 });
        }
    }
}