fix:调整httpserver脚本请求
This commit is contained in:
@@ -4,6 +4,7 @@ using System.Net;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using Valheim;
|
||||
|
||||
@@ -42,12 +43,13 @@ public class HttpServer : MonoBehaviour
|
||||
|
||||
void Awake()
|
||||
{
|
||||
DontDestroyOnLoad(gameObject);
|
||||
//DontDestroyOnLoad(gameObject)
|
||||
Task.Run(StartServer);
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
StartServer();
|
||||
|
||||
}
|
||||
|
||||
#region HTTP Server
|
||||
@@ -57,7 +59,7 @@ public class HttpServer : MonoBehaviour
|
||||
try
|
||||
{
|
||||
listener = new HttpListener();
|
||||
listener.Prefixes.Add(SERVER_URL);
|
||||
listener.Prefixes.Add($"http://{GetLocalIP()}:12345/");
|
||||
listener.Start();
|
||||
|
||||
isRunning = true;
|
||||
@@ -74,7 +76,18 @@ public class HttpServer : MonoBehaviour
|
||||
Debug.LogError("❌ HTTP Server 启动失败:" + e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user