示例#1
0
        private static void InitWifi()
        {
            // Declares the WiFly module, configures the IP address and joins a wireless network
            WiFlyGSX WifiModule = new WiFlyGSX(SerialPorts.COM1);
            WifiModule.EnableDHCP();
            WifiModule.JoinNetwork("BOKBOKBOK", 0, WiFlyGSX.AuthMode.MixedWPA1_WPA2, "bezout1983");
            

            // Showing some interesting output
            Debug.Print("Local IP: " + WifiModule.LocalIP);
            Debug.Print("MAC address: " + WifiModule.MacAddress);

            // Creates a socket
            var Socket = new WiFlySocket("www.netmftoolbox.com", 80, WifiModule);

            // Connects to the socket
            Socket.Connect();

            // Does a plain HTTP request
            Socket.Send("GET /helloworld/ HTTP/1.1\r\n");
            Socket.Send("Host: " + Socket.Hostname + "\r\n");
            Socket.Send("Connection: Close\r\n");
            Socket.Send("\r\n");

            // Prints all received data to the debug window, until the connection is terminated and there's no data left anymore
            while (Socket.IsConnected || Socket.BytesAvailable > 0)
            {
                string Text = Socket.Receive();
                if (Text != "")
                    Debug.Print(Text);
            }

            // Closes down the socket
            Socket.Close();
        }
示例#2
0
        public void FetchURL(Uri url)
        {
            bool success = false;
            while (!success)
            {
                var module = GetModule();

                var thread = new Thread(() =>
                {
                    var httpHost = url.Host;
                    var host = httpHost;
                    var port = (ushort)url.Port;

                    if (host == "pourcast.labs.rightpoint.com")
                        host = "192.168.100.114";

                    var request = "GET " + url.AbsolutePath + " HTTP/1.1\r\nHost: " + httpHost + "\r\nConnection: Close\r\n\r\n";
                    SimpleSocket socket = new WiFlySocket(host, port, module);

                    try
                    {
                        // Connects to the socket
                        socket.Connect();
                        // Does a plain HTTP request
                        socket.Send(request);

                        // Prints all received data to the debug window, until the connection is terminated
                        while (socket.IsConnected)
                        {
                            var line = socket.Receive().Trim();
                            if (line != "" && line != null)
                            {
                                //Debug.Print(line);
                            }
                        }
                        success = true;
                    }
                    finally
                    {
                        socket.Close();
                    }
                });
                thread.Start();

                using (var fetchWatchdog = new Watchdog(new TimeSpan(0, 0, 5), () =>
                {
                    Debug.Print("Triggering fetch watchdog");
                    thread.Abort();
                    Thread.Sleep(500);
                    module.Reboot();
                    module.Dispose();
                    _module = null;
                }))
                {
                    thread.Join();
                }
            }
        }
示例#3
0
文件: Program.cs 项目: cjdaly/napkin
 private string NapkinGet(string path)
 {
     try
     {
         WiFlySocket socket = new WiFlySocket(NapkinServerName, NapkinServerPort, _wifly);
         HTTP_Client client = new HTTP_Client(socket);
         client.Authenticate(DeviceId, DeviceId);
         HTTP_Client.HTTP_Response response = client.Get(path);
         return response.ResponseBody;
     }
     catch (Exception ex)
     {
         Debug.Print("Exception in PingServer: " + ex.Message);
         return null;
     }
 }