C# 地址已在使用中
我试图在Android应用程序中运行HTTP侦听器,但遇到了一个异常 SocketException:地址已在使用中 Unity Player不会产生错误,就像Windows版本一样。设备上的netstat显示。如果港口没有被任何人占用,会有什么问题? 也许有什么东西需要添加到清单中 我的代码(端口37273) 堆栈跟踪 05-08 07:42:15.751 4606 4699 E Unity:SocketException:地址已在使用中 05-08 07:42:15.751 4606 4699 E统一:在System.Net.Sockets.Socket.Bind(System.Net.EndPoint localEP)[0x00043]中:0 05-08 07:42:15.751 4606 4699 E Unity:at System.Net.EndPointListener..ctor(System.Net.HttpListener listener、System.Net.IPAddress addr、System.Int32端口、System.Boolean安全)[0x00047]in:0 05-08 07:42:15.751 4606 4699 E Unity:at System.Net.EndPointManager.GetEPListener(System.String主机、System.Int32端口、System.Net.HttpListener侦听器、System.Boolean安全)[0x0009d]in:0 05-08 07:42:15.751 4606 4699 E Unity:at System.Net.EndPointManager.AddPrefixInternal(System.String p,System.Net.HttpListener listener)[0x0005e]in:0 05-08 07:42:15.751 4606 4699 E Unity:在System.Net.EndPointManager.AddListener(System.Net.HttpListener listener)[0x0009c]中:0 05-08 07:42:15.751 4606 4699 E Unity:at System.Net.HttpListener.Start()[0x0000f]in:0 05-08 07:42:15.751 4606 4699 E Unity:在WebServer.Listen()[0x00093]中:0 05-08 07:42:15.751 4606 4699 E统一性:at System.Threading.ThreadHeC# 地址已在使用中,c#,android,http,unity3d,C#,Android,Http,Unity3d,我试图在Android应用程序中运行HTTP侦听器,但遇到了一个异常 SocketException:地址已在使用中 Unity Player不会产生错误,就像Windows版本一样。设备上的netstat显示。如果港口没有被任何人占用,会有什么问题? 也许有什么东西需要添加到清单中 我的代码(端口37273) 堆栈跟踪 05-08 07:42:15.751 4606 4699 E Unity:SocketException:地址已在使用中 05-08 07:42:15.751 4606 469
检查此代码是否只被调用一次,因为调用两次会使侦听器占用同一端口。问题得到解决,由于某种原因,Unity忽略了我的安全配置,并插入了自己的,将ClearTextTrafficAllowed更改为false
private void Listen()
{
Debug.Log("START HTTP LISTENIER!");
listener = new HttpListener();
listener.Prefixes.Add("http://localhost:" + port.ToString() + "/");
listener.Prefixes.Add("http://127.0.0.1:" + port.ToString() + "/");
listener.Prefixes.Add("http://*:" + port.ToString() + "/");
listener.Start();
while (connect)
{
try
{
Process(listener.GetContext());
}
catch (Exception ex)
{
Debug.Log("HTTP listener context Exeption: " + ex.ToString() + "\n " + ex.Message);
}
}
}