我开发的全息镜头2在统一,现在遇到了一个问题的套接字通信。我正在hololens 2上尝试获取TCP客户端,如果我想连接到TCP服务器,我眼镜上出现了以下错误(统一工作):System.Exception:试图以其访问权限禁止的方式访问套接字。
我已经检查了Player设置中的权限: InternetClient、InternetClientServer、PrivateNetworkClientServer
使用的
团结2019.4.2f1
Api兼容性级别.NET 4.x
脚本后端: IL2CPP
目标SDK版本: 10.0.18362.0
使用: Windows.Networking.Sockets.StreamSocket
有什么建议吗?
发布于 2021-05-28 03:12:58
我使用的是Unity2019.4.13f1,tcp连接可以正常工作。
示例代码:
public string ServerIp = "192.168.31.12";
private const int PORT = 9999;
private Socket Client;
public void CreateClient()
{
Debug.Log("\r\nCreating Client...");
Thread createClientAndConnect = new Thread(() =>
{
try
{
IPEndPoint serverEP = new IPEndPoint(IPAddress.Parse(ServerIp), PORT);
Client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
Client.Connect(serverEP);
Thread listenToServer = new Thread(Receive);
listenToServer.IsBackground = true;
listenToServer.Start(Client);
}
catch (Exception e)
{
Debug.LogError("Error when creating client");
Debug.LogError(e.Message);
}
});
createClientAndConnect.IsBackground = true;
createClientAndConnect.Start();
Debug.Log("Client is created");
}https://stackoverflow.com/questions/64022164
复制相似问题