Created
June 2, 2021 08:06
-
-
Save valentinbreiz/1995e42b9e214fab8772e8080d4ddfd1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Cosmos.HAL; | |
using Cosmos.System.Network; | |
using Cosmos.System.Network.ARP; | |
using Cosmos.System.Network.Config; | |
using Cosmos.System.Network.IPv4; | |
using Cosmos.System.Network.IPv4.TCP; | |
using Cosmos.System.Network.IPv4.UDP; | |
using Cosmos.System.Network.IPv4.UDP.DHCP; | |
using Cosmos.System.Network.IPv4.UDP.DNS; | |
using Cosmos.TestRunner; | |
using SimpleHttpServer; | |
using SimpleHttpServer.Models; | |
using System; | |
using System.Collections.Generic; | |
using System.Text; | |
using Sys = Cosmos.System; | |
namespace NetworkTest | |
{ | |
public class Kernel : Sys.Kernel | |
{ | |
protected override void BeforeRun() | |
{ | |
NetworkDevice nic = NetworkDevice.GetDeviceByName("eth0"); //get network device by name | |
//IPConfig.Enable(nic, Address.Parse("10.33.20.54"), new Address(255, 255, 255, 0), Address.Parse("10.33.20.254")); //enable IPv4 configuration | |
IPConfig.Enable(nic, new Address(10, 33, 20, 54), new Address(255, 255, 255, 0), new Address(10, 33, 20, 254)); //enable IPv4 configuration | |
Console.WriteLine("Network config done! IP=" + NetworkConfig.CurrentConfig.Value.IPAddress.ToString()); | |
} | |
protected override void Run() | |
{ | |
try | |
{ | |
var route_config = new List<Route>() { | |
new Route { | |
Name = "Hello Handler", | |
Method = "GET", | |
Callable = (HttpDiscussion result) => { | |
result.Response = new HttpResponse() | |
{ | |
Content = @"<html>" + | |
"\t<h1>Hello from CosmosOS!</h1>" + | |
"\t<p>Server hour: " + DateTime.Now.ToString() + "</p>" + | |
"</html>", | |
ReasonPhrase = "OK", | |
StatusCode = "200" | |
}; | |
} | |
}, | |
}; | |
HttpServer httpServer = new HttpServer(80, route_config); | |
httpServer.Listen(); | |
} | |
catch (Exception ex) | |
{ | |
Console.WriteLine("Exception: " + ex); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment