Skip to content

Instantly share code, notes, and snippets.

@kumpera
Created September 2, 2011 20:00
Show Gist options
  • Save kumpera/1189722 to your computer and use it in GitHub Desktop.
Save kumpera/1189722 to your computer and use it in GitHub Desktop.
using System;
using System.IO;
using System.Net;
namespace ConsoleApplication1 {
class Class1 {
static void Main ()
{
HttpListener l = new HttpListener ();
//l.Prefixes.Add ("https://*:9667/");
l.Prefixes.Add ("http://*:9667/");
l.Start ();
l.BeginGetContext (OnGetContext, l);
Console.ReadLine ();
}
static void OnGetContext (IAsyncResult ares)
{
HttpListener l = ares.AsyncState as HttpListener;
if (l == null)
return;
try {
HttpListenerContext ctx = l.EndGetContext (ares);
Console.WriteLine ("Got request");
l.BeginGetContext (OnGetContext, l);
ctx.Response.KeepAlive = true;
using (StreamWriter writer = new StreamWriter (ctx.Response.OutputStream))
writer.Write ("Hello world!");
ctx.Response.Close ();
Console.WriteLine ("Sent request");
} catch (Exception e) {
Console.WriteLine (e);
Environment.Exit (1);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment