HttpServer.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Net;
  6. using System.Net.Sockets;
  7. using System.Text;
  8. using System.Threading;
  9. namespace ZLPlugin_LisPacs_MR_YJMZ
  10. {
  11. public abstract class HttpServer
  12. {
  13. protected int port;
  14. TcpListener listener;
  15. bool is_active = true;
  16. public HttpServer(int port)
  17. {
  18. this.port = port;
  19. }
  20. public void listen()
  21. {
  22. IPAddress ip = IPAddress.Parse("127.0.0.1");
  23. listener = new TcpListener(ip, port);
  24. listener.Start();
  25. while (is_active)
  26. {
  27. TcpClient s = listener.AcceptTcpClient();
  28. HttpProcessor processor = new HttpProcessor(s, this);
  29. Thread thread = new Thread(new ThreadStart(processor.process));
  30. thread.Start();
  31. Thread.Sleep(1);
  32. }
  33. }
  34. public abstract void handleGETRequest(HttpProcessor p);
  35. public abstract void handlePOSTRequest(HttpProcessor p, StreamReader inputData);
  36. }
  37. }