修改HttpServer,进入速度加快

This commit is contained in:
2026-02-11 15:49:23 +08:00
parent a53dc494a8
commit 6e73118bd9
3 changed files with 20 additions and 11 deletions

View File

@@ -6,6 +6,7 @@ using System.Threading;
using System.Collections.Concurrent;
using UnityEngine;
using Valheim;
using System.Threading.Tasks;
[Serializable]
public class IntentMessage
@@ -42,12 +43,13 @@ public class HttpServer : MonoBehaviour
void Awake()
{
DontDestroyOnLoad(gameObject);
Task.Run(StartServer);
}
void Start()
{
StartServer();
}
#region HTTP Server
@@ -57,15 +59,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}");
}
@@ -75,6 +73,17 @@ 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)