.net gadgeteer网络事件没有解雇。没有得到Web服务器的响应

时间:2016-12-24 16:56:59

标签: c# .net-micro-framework .net-gadgeteer

这是下面的代码。

    using System;
using System.Collections;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.Presentation.Media;
using Microsoft.SPOT.Presentation.Shapes;
using Microsoft.SPOT.Touch;

using Gadgeteer.Networking;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
using Microsoft.SPOT.Net.NetworkInformation;


namespace WebSer
{
    public partial class Program
    {
        GT.Networking.WebEvent sayHello;
        GT.Timer t;
        void ProgramStarted()
        {
            t = new GT.Timer(1000);
            t.Tick += new GT.Timer.TickEventHandler(t_Tick);
            t.Start();
        }

        private void t_Tick(GT.Timer timer)
        {
            t.Stop();
            if (!wifi.NetworkInterface.Opened)
                wifi.NetworkInterface.Open();
            if (!wifi.NetworkInterface.IsDhcpEnabled)
                wifi.NetworkInterface.EnableDhcp();
            wifi.NetworkInterface.NetworkInterface.EnableDynamicDns();

            NetworkChange.NetworkAddressChanged += NetworkChange_NetworkAddressChanged;
            NetworkChange.NetworkAvailabilityChanged += NetworkChange_NetworkAvailabilityChanged;
           wifi.NetworkInterface.Join("Connectify-test", "abdi1990");
           while (true)
            {
                string ipaddress = wifi.NetworkInterface.IPAddress;
                Debug.Print(ipaddress);

                if (ipaddress != "0.0.0.0") break;

                Thread.Sleep(1000);
            }
            Thread.Sleep(-1);   
        }

        private void NetworkChange_NetworkAvailabilityChanged(object sender, NetworkAvailabilityEventArgs e)
        {
            Debug.Print("CHANGED");

        }

        private void NetworkChange_NetworkAddressChanged(object sender, EventArgs e)
        {
            Debug.Print(wifi.NetworkInterface.IPAddress+"from event");
            if (wifi.NetworkInterface.IPAddress != "0.0.0.0")
            {
                WebServer.StartLocalServer(wifi.NetworkInterface.IPAddress, 80);
                sayHello = WebServer.SetupWebEvent("hello");
                sayHello.WebEventReceived+=sayHello_WebEventReceived;
                // wifi_RS21.Interface.Disconnect();
            }
        }

        private 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");
        }


    }
}

连接时的输出是这个

The thread '<No Name>' (0x2) has exited with code 0 (0x0).
Using mainboard GHI Electronics FEZ Spider version 1.0
The thread '<No Name>' (0x3) has exited with code 0 (0x0).
0.0.0.0
0.0.0.0
CHANGED
192.168.137.102from event
Web server started at http://192.168.137.102:80/
192.168.137.102

然后当我转到192.168.137.102:80时,它会在末尾输出另外两行 并正确显示默认站点。我还附上了图片

The thread '<No Name>' (0x2) has exited with code 0 (0x0).
Using mainboard GHI Electronics FEZ Spider version 1.0
The thread '<No Name>' (0x3) has exited with code 0 (0x0).
0.0.0.0
0.0.0.0
CHANGED
192.168.137.102from event
Web server started at http://192.168.137.102:80/
192.168.137.102
The thread '<No Name>' (0x7) has exited with code 0 (0x0).
The thread '<No Name>' (0x8) has exited with code 0 (0x0).

Default site

然后如果转到192.168.137.102:80/hello没有任何反应,浏览器会继续加载并在底部输出两个以上的东西

The thread '<No Name>' (0x2) has exited with code 0 (0x0).
Using mainboard GHI Electronics FEZ Spider version 1.0
The thread '<No Name>' (0x3) has exited with code 0 (0x0).
0.0.0.0
0.0.0.0
CHANGED
192.168.137.102from event
Web server started at http://192.168.137.102:80/
192.168.137.102
The thread '<No Name>' (0x7) has exited with code 0 (0x0).
The thread '<No Name>' (0x8) has exited with code 0 (0x0).
The thread '<No Name>' (0x9) has exited with code 0 (0x0).
The thread '<No Name>' (0xa) has exited with code 0 (0x0).

因此默认的192.168.137.102:80有效,但192.168.137.102:80/hello没有。 我需要帮助。

1 个答案:

答案 0 :(得分:1)

我认为这是Webserver API中的一个错误,您可以修复它:

https://gadgeteer.codeplex.com/workitem/1861

您在GHI文档站点42中找到了一个教程: https://www.ghielectronics.com/downloads/Gadgeteer/NET_Gadgeteer_for_beginners.pdf

希望它有所帮助...