| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Net;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace WindowsServiceClient
- {
- static class Program
- {
- /// <summary>
- /// 应用程序的主入口点。
- /// </summary>
- [STAThread]
- static void Main()
- {
- Start();
- Application.EnableVisualStyles();
- Application.SetCompatibleTextRenderingDefault(false);
- Application.Run(new Form1());
- }
- private static void Start()
- {
- HttpListener httpListenner;
- httpListenner = new HttpListener();
- httpListenner.AuthenticationSchemes = AuthenticationSchemes.Anonymous;
- httpListenner.Prefixes.Add("http://localhost:4033/");
- httpListenner.Start();
- new Thread(new ThreadStart(delegate {
- try
- {
- loop(httpListenner);
- httpListenner.Stop();
- }
- catch (Exception ex)
- {
- var ddd = ex.Message;
- httpListenner.Stop();
- }
- })).Start();
- }
- private static void loop(HttpListener httpListenner)
- {
- while (true)
- {
- HttpListenerContext context = httpListenner.GetContext();
- HttpListenerRequest request = context.Request;
- HttpListenerResponse response = context.Response;
- Servlet servlet = new MyServlet();
- servlet.onCreate();
- if (request.HttpMethod == "POST")
- {
- servlet.onPost(request, response);
- }
- else if (request.HttpMethod == "GET")
- {
- servlet.onGet(request, response);
- }
- response.Close();
- }
- }
-
- }
- }
|