首次提交:添加src文件夹代码
This commit is contained in:
47
Cowain.Bake.Communication/Sokects/HttpServer.cs
Normal file
47
Cowain.Bake.Communication/Sokects/HttpServer.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user