public override void handleGETRequest(HttpProcessor p) { switch (p.http_url) { case "/close": p.writeSuccess(); p.outputStream.WriteLine(CloseDocument()); break; case "/": case "/songs": p.writeSuccess(); p.outputStream.WriteLine(SongsDocument()); break; case "/songs/current": p.writeSuccess(); p.outputStream.WriteLine(CurrentSongJson()); break; default: Console.WriteLine("request: {0}", p.http_url); p.writeSuccess(); p.outputStream.WriteLine("<html><body><h1>404 Not Found</h1>"); p.outputStream.WriteLine("Current Time: " + DateTime.Now.ToString()); p.outputStream.WriteLine("url : {0}", p.http_url); p.outputStream.WriteLine("</body></html>"); break; } }
public override void handlePOSTRequest(HttpProcessor p, StreamReader inputData) { string data = inputData.ReadToEnd(); switch (p.http_url) { case "/songs/play": string songGuid = data.Replace("id=", string.Empty); HtmlData.OnPlaySong(songGuid); p.writeSuccess(); break; case "/songs/shuffle": HtmlData.OnShufflePlay(); p.writeSuccess(); break; case "/songs/playpause": HtmlData.OnPlayPause(); p.writeSuccess(); break; default: break; } }
public void Listen() { listener = new TcpListener(port); listener.Start(); while (IsActive) { TcpClient s = listener.AcceptTcpClient(); HttpProcessor processor = new HttpProcessor(s, this); Thread thread = new Thread(new ThreadStart(processor.process)); thread.Start(); Thread.Sleep(1); } }
public abstract void handlePOSTRequest(HttpProcessor p, StreamReader inputData);
public abstract void handleGETRequest(HttpProcessor p);