示例#1
0
        /// <summary>
        /// Main.
        /// </summary>
        /// <param name="myArgs">The arguments.</param>
        public static void Main(String[] myArgs)
        {
            #region Start TCPServers

            //var _TCPServer1 = new TCPServer(new IPv4Address(new Byte[] { 192, 168, 178, 31 }), new IPPort(2001), NewConnection =>
            //                                   {
            //                                       NewConnection.WriteToResponseStream("Hello world!" + Environment.NewLine + Environment.NewLine);
            //                                       NewConnection.Close();
            //                                   }, true);

            //Console.WriteLine(_TCPServer1);

            // The first line of the repose will be served from the CustomTCPConnection handler.
            var _TCPServer2 = new TCPServer <CustomTCPConnection>(IPv4Address.Any, new IPPort(2002), NewConnection =>
            {
                NewConnection.WriteToResponseStream("...world!" + Environment.NewLine + Environment.NewLine);
                NewConnection.Close();
            }, true);

            Console.WriteLine(_TCPServer2);

            #endregion

            #region Start HTTPServers

            // Although the socket listens on IPv4Address.Any the service is
            // configured to serve clients only on http://localhost:8181
            // More details within DefaultHTTPService.cs
            var _HTTPServer1 = new HTTPServer(IPv4Address.Any, new IPPort(8181), Autostart: true)
            {
                ServerName = "Default Hermod Demo"
            };

            Console.WriteLine(_HTTPServer1);

            // This service uses a custom HTTPService defined within IRESTService.cs
            var _HTTPServer2 = new HTTPServer <IRESTService>(IPv4Address.Any, IPPort.HTTP, Autostart: true)
            {
                ServerName = "Customized Hermod Demo"
            };

            Console.WriteLine(_HTTPServer2);

            #endregion

            #region UDP Servers

            var _UDPServer1 = new UDPServer(new IPPort(5555), NewPacket =>
            {
                //NewPacket.Data = new Byte[10];
                //   NewPacket.Close();
            }, true);

            #endregion

            var _client1 = new HTTPClient(IPv4Address.Localhost, IPPort.HTTP);

            var _request0 = _client1.GET("/HelloWorld").
                            SetHost("localhorst").
                            AddAccept(HTTPContentType.TEXT_UTF8, 1);

            var _request1 = _client1.GET("/HelloWorld").
                            SetHost("localhorst").
                            AddAccept(HTTPContentType.HTML_UTF8, 1);

            //WriteRequest(_request0.EntireRequestHeader);

            //_client1.Execute(_request0, response => WriteResponse(response.Content.ToUTF8String())).
            //         ContinueWith(HTTPClient => { WriteRequest(_request1.EntireRequestHeader); return HTTPClient.Result; }).
            //         ContinueWith(HTTPClient => HTTPClient.Result.Execute(_request1, response => WriteResponse(response.Content.ToUTF8String()))).
            //         Wait();

            var _client2  = new HTTPClient(IPv4Address.Parse("188.40.47.229"), IPPort.HTTP);
            var _requestA = _client2.GET("/").
                            SetProtocolVersion(HTTPVersion.HTTP_1_1).
                            SetHost("www.ahzf.de").
                            SetUserAgent("Hermod HTTP Client v0.1").
                            SetConnection("keep-alive").
                            AddAccept(HTTPContentType.HTML_UTF8, 1);

            var _requestB = _client2.GET("/nfgj").
                            SetProtocolVersion(HTTPVersion.HTTP_1_1).
                            SetHost("www.ahzf.de").
                            SetUserAgent("Hermod HTTP Client v0.1").
                            SetConnection("keep-alive").
                            AddAccept(HTTPContentType.HTML_UTF8, 1);

            WriteRequest(_requestA);
            _client2.Execute(_requestA, response => WriteResponse(response)).
            ContinueWith(Client => Client.Result.Execute(_requestB, response => WriteResponse(response)));


            var _req23a = new HTTPRequestBuilder().
                          SetHTTPMethod(HTTPMethod.GET).
                          SetProtocolName("µHTTP").
                          SetProtocolVersion(new HTTPVersion(2, 0)).
                          SetHost("localhorst").
                          SetUserAgent("Hermod µHTTP Client").
                          SetContent("This the HTTP content...");

            _req23a.QueryString.Add("name", "alice").
            Add("friend", "bob").
            Add("friend", "carol");

            var _req23b = new HTTPRequestBuilder()
            {
                HTTPMethod      = HTTPMethod.GET,
                ProtocolName    = "µHTTP",
                ProtocolVersion = new HTTPVersion(2, 0),
                Host            = "localhorst",
                UserAgent       = "Hermod µHTTP Client",
                Content         = "This the HTTP content...".ToUTF8Bytes()
            };


//            var Response = new TCPClientRequest("localhost", 80).Send("GETTT / HTTP/1.1").FinishCurrentRequest().Response;

            Console.ReadLine();
            Console.WriteLine("done!");
        }
示例#2
0
        protected override void BeforeRun()
        {
            Console.Clear();
            #region Register additional network cards
            int i = 1;
            foreach (PCIDevice device in PCI.Devices)
            {
                if ((device.ClassCode == 0x02) && (device.Subclass == 0x00) && // is Ethernet Controller
                    device == PCI.GetDevice(device.bus, device.slot, device.function))
                {
                    Console.WriteLine("Found " + PCIDevice.DeviceClass.GetDeviceString(device) + " on PCI " + device.bus + ":" + device.slot + ":" + device.function);


                    if (device.VendorID == 0x10EC && device.DeviceID == 0x8168)
                    {
                        Console.WriteLine("RTL8168 NIC IRQ: " + device.InterruptLine);

                        var RTL8168Device = new RTL8168(device);

                        RTL8168Device.NameID = "eth" + i;

                        Console.WriteLine("Registered at " + RTL8168Device.NameID + " (" + RTL8168Device.MACAddress.ToString() + ")");

                        RTL8168Device.Enable();
                        i++;
                    }
                }
            }
            foreach (var item in Intel8254X.FindAll())
            {
                item.NameID = "eth" + i;
                item.Enable();
                Console.WriteLine("Registered at " + item.NameID + " (" + item.MACAddress.ToString() + ")");
                i++;
            }
            #endregion
            try
            {
                using (var xClient = new DHCPClient())
                {
                    /** Send a DHCP Discover packet **/
                    //This will automatically set the IP config after DHCP response
                    NetworkStack.Update();
                    int r = xClient.SendDiscoverPacket();
                    if (r == -1)
                    {
                        Console.WriteLine("Failure while configuring DHCP: timeout");
                        xClient.Close();
                        return;
                    }
                    else
                    {
                        Console.WriteLine("DHCP Configure: result: " + r);
                    }
                    xClient.Close();  //don't forget to close!
                }
                ipconfig();
            }
            catch (Exception x)
            {
                Console.WriteLine("err: " + x.Message);
            }

            NTPClient client = new NTPClient();
            var       t      = client.GetNetworkTime();
            Console.WriteLine("Curent time: " + t);

            HTTPClient http     = new HTTPClient("github.com");
            var        responce = http.GET("/test.html");
            Console.WriteLine("====");
            Console.WriteLine(responce);
        }
示例#3
0
        /// <summary>
        /// Main.
        /// </summary>
        /// <param name="myArgs">The arguments.</param>
        public static void Main(String[] myArgs)
        {
            #region Start TCPServers

            //var _TCPServer1 = new TCPServer(new IPv4Address(new Byte[] { 192, 168, 178, 31 }), new IPPort(2001), NewConnection =>
            //                                   {
            //                                       NewConnection.WriteToResponseStream("Hello world!" + Environment.NewLine + Environment.NewLine);
            //                                       NewConnection.Close();
            //                                   }, true);

            //Console.WriteLine(_TCPServer1);

            // The first line of the repose will be served from the CustomTCPConnection handler.
            var _TCPServer2 = new TCPServer<CustomTCPConnection>(IPv4Address.Any, new IPPort(2002), NewConnection =>
                                               {
                                                   NewConnection.WriteToResponseStream("...world!" + Environment.NewLine + Environment.NewLine);
                                                   NewConnection.Close();
                                               }, true);

            Console.WriteLine(_TCPServer2);

            #endregion

            #region Start HTTPServers

            // Although the socket listens on IPv4Address.Any the service is
            // configured to serve clients only on http://localhost:8181
            // More details within DefaultHTTPService.cs
            var _HTTPServer1 = new HTTPServer(IPv4Address.Any, new IPPort(8181), Autostart: true)
                                   {
                                       ServerName = "Default Hermod Demo"
                                   };

            Console.WriteLine(_HTTPServer1);

            // This service uses a custom HTTPService defined within IRESTService.cs
            var _HTTPServer2 = new HTTPServer<IRESTService>(IPv4Address.Any, IPPort.HTTP, Autostart: true)
                                   {
                                       ServerName = "Customized Hermod Demo"
                                   };

            Console.WriteLine(_HTTPServer2);

            #endregion

            #region UDP Servers

            var _UDPServer1 = new UDPServer(new IPPort(5555), NewPacket =>
            {
                //NewPacket.Data = new Byte[10];
             //   NewPacket.Close();
            }, true);

            #endregion

            var _client1     = new HTTPClient(IPv4Address.Localhost, IPPort.HTTP);

            var _request0    = _client1.GET("/HelloWorld").
                                        SetHost("localhorst").
                                        AddAccept(HTTPContentType.TEXT_UTF8, 1);

            var _request1    = _client1.GET("/HelloWorld").
                                        SetHost("localhorst").
                                        AddAccept(HTTPContentType.HTML_UTF8, 1);

            //WriteRequest(_request0.EntireRequestHeader);

            //_client1.Execute(_request0, response => WriteResponse(response.Content.ToUTF8String())).
            //         ContinueWith(HTTPClient => { WriteRequest(_request1.EntireRequestHeader); return HTTPClient.Result; }).
            //         ContinueWith(HTTPClient => HTTPClient.Result.Execute(_request1, response => WriteResponse(response.Content.ToUTF8String()))).
            //         Wait();

            var _client2 = new HTTPClient(IPv4Address.Parse("188.40.47.229"), IPPort.HTTP);
            var _requestA = _client2.GET("/").
                                     SetProtocolVersion(HTTPVersion.HTTP_1_1).
                                     SetHost("www.ahzf.de").
                                     SetUserAgent("Hermod HTTP Client v0.1").
                                     SetConnection("keep-alive").
                                     AddAccept(HTTPContentType.HTML_UTF8, 1);

            var _requestB = _client2.GET("/nfgj").
                                     SetProtocolVersion(HTTPVersion.HTTP_1_1).
                                     SetHost("www.ahzf.de").
                                     SetUserAgent("Hermod HTTP Client v0.1").
                                     SetConnection("keep-alive").
                                     AddAccept(HTTPContentType.HTML_UTF8, 1);

            WriteRequest(_requestA);
            _client2.Execute(_requestA, response => WriteResponse(response)).
                     ContinueWith(Client => Client.Result.Execute(_requestB, response => WriteResponse(response)));

            var _req23a = new HTTPRequestBuilder().
                              SetHTTPMethod      (HTTPMethod.GET).
                              SetProtocolName    ("µHTTP").
                              SetProtocolVersion (new HTTPVersion(2, 0)).
                              SetHost            ("localhorst").
                              SetUserAgent       ("Hermod µHTTP Client").
                              SetContent         ("This the HTTP content...");

            _req23a.QueryString.Add("name",   "alice").
                                Add("friend", "bob").
                                Add("friend", "carol");

            var _req23b = new HTTPRequestBuilder() {
                              HTTPMethod        = HTTPMethod.GET,
                              ProtocolName      = "µHTTP",
                              ProtocolVersion   = new HTTPVersion(2, 0),
                              Host              = "localhorst",
                              UserAgent         = "Hermod µHTTP Client",
                              Content           = "This the HTTP content...".ToUTF8Bytes()
                          };

            //            var Response = new TCPClientRequest("localhost", 80).Send("GETTT / HTTP/1.1").FinishCurrentRequest().Response;

            Console.ReadLine();
            Console.WriteLine("done!");
        }