修改HttpServer,进入速度加快

This commit is contained in:
2026-02-11 15:55:56 +08:00
parent 3a7b2d560a
commit 08c82a485d
22 changed files with 26467 additions and 505 deletions

View File

@@ -5,6 +5,7 @@ using System.Text;
using System.Threading;
using System.Collections.Concurrent;
using UnityEngine;
using System.Threading.Tasks;
[Serializable]
public class IntentMessage
@@ -41,12 +42,12 @@ public class HttpServer : MonoBehaviour
void Awake()
{
DontDestroyOnLoad(gameObject);
Task.Run(StartServer);
}
void Start()
{
StartServer();
}
#region HTTP Server
@@ -56,15 +57,11 @@ public class HttpServer : MonoBehaviour
try
{
listener = new HttpListener();
listener.Prefixes.Add(SERVER_URL);
listener.Prefixes.Add($"http://{GetLocalIP()}:12345/");
listener.Start();
isRunning = true;
serverThread = new Thread(ListenLoop)
{
IsBackground = true
};
serverThread.Start();
ListenLoop();
Debug.Log($"✅ HTTP Server 启动成功:{SERVER_URL}");
}
@@ -74,6 +71,19 @@ public class HttpServer : MonoBehaviour
}
}
private string GetLocalIP()
{
var host = System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName());
foreach (var ip in host.AddressList)
{
if (ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
return ip.ToString();
}
return "127.0.0.1";
}
private void ListenLoop()
{
while (isRunning && listener.IsListening)