首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >hololens 2 tcp客户端访问权限

hololens 2 tcp客户端访问权限
EN

Stack Overflow用户
提问于 2020-09-23 06:26:31
回答 1查看 1.5K关注 0票数 0

我开发的全息镜头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

有什么建议吗?

EN

回答 1

Stack Overflow用户

发布于 2021-05-28 03:12:58

我使用的是Unity2019.4.13f1,tcp连接可以正常工作。

示例代码:

代码语言:javascript
复制
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");
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64022164

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档