HttpServer, HttpProcessor and IHttpHandler.
This commit is contained in:
39
VAR.HttpServer.MiniServerTest/Program.cs
Normal file
39
VAR.HttpServer.MiniServerTest/Program.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace VAR.HttpServer.MiniServerTest
|
||||
{
|
||||
internal class Program
|
||||
{
|
||||
private static void Main(string[] args)
|
||||
{
|
||||
HttpServer httpServer = new HttpServer
|
||||
{
|
||||
Port = 3000,
|
||||
Handler = new HelloWorldHttpHandler(),
|
||||
LogDegugMessage = (msg) => Console.WriteLine("DEBUG: {0}", msg),
|
||||
LogException = (ex) =>
|
||||
{
|
||||
Console.WriteLine("!!!!! Exception !!!!");
|
||||
Console.WriteLine("Message: {0}", ex.Message);
|
||||
Console.WriteLine("StackTrace: {0}", ex.StackTrace);
|
||||
}
|
||||
};
|
||||
Console.Title = string.Format("MiniHTTPServer@{0}", httpServer.Port);
|
||||
Console.WriteLine("HTTP Server started on {0} port", httpServer.Port);
|
||||
httpServer.Start();
|
||||
|
||||
Process proc = Process.Start(string.Format("http://localhost:{0}", httpServer.Port));
|
||||
}
|
||||
|
||||
public class HelloWorldHttpHandler : IHttpHandler
|
||||
{
|
||||
public void HandleRequest(HttpProcessor p)
|
||||
{
|
||||
Console.WriteLine("Responding to {0}", p.Socket.Client.RemoteEndPoint);
|
||||
p.ResponseSuccess();
|
||||
p.OutputStream.WriteLine("Hello World!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user