User Defined HTTP SERVER in C#
using System;
using System.Linq;
using System.Net;
using System.Threading;
namespace ConsoleApplication3
{
class Program
{
public static HttpListener _list = new HttpListener();
static void Main(string[] args)
{
_list.Prefixes.Add("http://localhost:2000/");
_list.Start()
Console.WriteLine("server started");
Thread th = new Thread(loadsite);
th.Start();
Console.Read();
}
protected static void loadsite()
{
while (true)
{
HttpListenerContext context = _list.GetContext();
byte[] response = Encoding.UTF8.GetBytes("<html><body>hello world</body></html>");
context.Response.OutputStream.Write(response, 0, response.Length);
context.Response.KeepAlive = false;
context.Response.Close();
}
}
}
using System;
using System.Linq;
using System.Net;
using System.Threading;
namespace ConsoleApplication3
{
class Program
{
public static HttpListener _list = new HttpListener();
static void Main(string[] args)
{
_list.Prefixes.Add("http://localhost:2000/");
_list.Start()
Console.WriteLine("server started");
Thread th = new Thread(loadsite);
th.Start();
Console.Read();
}
protected static void loadsite()
{
while (true)
{
HttpListenerContext context = _list.GetContext();
byte[] response = Encoding.UTF8.GetBytes("<html><body>hello world</body></html>");
context.Response.OutputStream.Write(response, 0, response.Length);
context.Response.KeepAlive = false;
context.Response.Close();
}
}
}