public static void OnRequest(HTTPRequest Request, ref NetworkStream ns)
        {
            string HeadersString = Request._HTTPResponse.version + " " + Request.Parent.respStatus[Request._HTTPResponse.status] + "\r\n";

            //***Put Custom Handling Here!
            Request._HTTPResponse.Headers.Add("Content-Type", "text/plain");

            SendHeaders(HeadersString, Request._HTTPResponse.Headers, ref ns);

            // Send body
            Request._HTTPResponse.BodyData = new ASCIIEncoding().GetBytes(_DefaultResponse);
            if (Request._HTTPResponse.BodyData != null)
            ns.Write(Request._HTTPResponse.BodyData, 0, Request._HTTPResponse.BodyData.Length);
        }
Example #2
0
        public void Listen()
        {
            try
            {
                bool done = false;

                listener = new TcpListener(new IPEndPoint(IPAddress.Any, portNum));

                listener.Start();

                while (!done)
                {
                    //Waiting for connection...
                    HTTPRequest newRequest = new HTTPRequest(listener.AcceptTcpClient(), this);
                    Thread Thread = new Thread(new ThreadStart(newRequest.Process));
                    Thread.Name = "HTTP Request";
                    Thread.Start();
                }
            }
            catch (ThreadAbortException)
            {
                Console.WriteLine("Aborting listener...");
            }
            catch(Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }