public override void handleGETRequest(HttpProcessor p) { if (p.http_url.StartsWith("/disp")) { byte[] data = ImgSource.GetImage(); p.httpResponseHeaders["Cache-Control"] = "no-cache, must-revalidate"; p.writeSuccess("image/jpeg"); p.outputStream.Flush(); p.outputStream.BaseStream.Write(data,0,data.Length); p.outputStream.BaseStream.Flush(); } else if (p.http_url.StartsWith("/left")) { byte[] data = ImgSource.GetLeftImage(); p.httpResponseHeaders["Cache-Control"] = "no-cache, must-revalidate"; p.writeSuccess("image/jpeg"); p.outputStream.Flush(); p.outputStream.BaseStream.Write(data,0,data.Length); p.outputStream.BaseStream.Flush(); } else if (p.http_url.StartsWith("/right")) { byte[] data = ImgSource.GetRightImage(); p.httpResponseHeaders["Cache-Control"] = "no-cache, must-revalidate"; p.writeSuccess("image/jpeg"); p.outputStream.Flush(); p.outputStream.BaseStream.Write(data,0,data.Length); p.outputStream.BaseStream.Flush(); } else if (p.http_url == "/main.css") { p.writeSuccess("text/css"); string txt = File.ReadAllText("Server/main.css"); p.outputStream.Write(txt); } else if (p.http_url == "/jquery.js") { p.writeSuccess("text/javascript"); string txt = File.ReadAllText("Server/jquery.js"); p.outputStream.Write(txt); } else if (p.http_url == "/main.js") { p.writeSuccess("text/javascript"); string txt = File.ReadAllText("Server/main.js"); p.outputStream.Write(txt); } else if (p.http_url == "" || p.http_url == "/" || p.http_url == "/index") { p.writeSuccess(); string txt = File.ReadAllText("Server/main.html"); p.outputStream.Write(txt); } else { p.writeSuccess(); p.outputStream.Write(p.http_url); } }
public override void handlePOSTRequest(HttpProcessor p, System.IO.StreamReader inputData) { }
public void listen() { listener = new TcpListener(IPAddress.Any,port); listener.Start(); while (is_active) { if (listener.Pending()) { TcpClient s = listener.AcceptTcpClient(); s.SendTimeout = 120*1000; //milliseconds HttpProcessor processor = new HttpProcessor(s, this); Thread thread = new Thread(new ThreadStart(processor.process)); thread.Start(); } Thread.Sleep(100); } listener.Stop(); }
public abstract void handlePOSTRequest(HttpProcessor p, StreamReader inputData);
public abstract void handleGETRequest(HttpProcessor p);