40 lines
1.3 KiB
C#
40 lines
1.3 KiB
C#
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!");
|
|
}
|
|
}
|
|
}
|
|
}
|