48 lines
1.4 KiB
C#
48 lines
1.4 KiB
C#
using Cowain.Bake.Common.Interface;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Net;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Unity;
|
|
|
|
namespace Cowain.Bake.Communication.Sokects
|
|
{
|
|
public class HttpServer
|
|
{
|
|
IRecvMesHttp MesServer { get; set; }
|
|
IUnityContainer _unityContainer;
|
|
public HttpServer(IUnityContainer unityContainer)
|
|
{
|
|
_unityContainer = unityContainer;
|
|
}
|
|
|
|
public void Start()
|
|
{
|
|
using (HttpListener listener = new HttpListener())
|
|
{
|
|
listener.Prefixes.Add("http://localhost:8089/");
|
|
listener.Start();
|
|
|
|
while (true)
|
|
{
|
|
HttpListenerContext context = listener.GetContext();
|
|
HttpListenerRequest request = context.Request;
|
|
HttpListenerResponse response = context.Response;
|
|
//string url = request.Url.AbsolutePath;
|
|
string replyData = MesServer.RecvInfo(request);
|
|
|
|
byte[] buffer = Encoding.UTF8.GetBytes(replyData);
|
|
response.ContentLength64 = buffer.Length;
|
|
Stream output = response.OutputStream;
|
|
output.Write(buffer, 0, buffer.Length);
|
|
output.Close();
|
|
response.Close();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|