Hololens上的UDP套接字:“创建套接字至少需要一种网络功能。”

时间:2018-08-24 14:00:21

标签: udp hololens

尽管我在播放器设置中授予了“ PrivateNetworkClientServer”的许可,但我还是从标题中得到了错误(我也尝试过“ InternetClientServer”)。

我在Unity中获得了以下代码:

using UnityEngine;
using System;
using System.IO;

#if !UNITY_EDITOR
using Windows.Networking.Sockets;
#endif

public class HololensUDPServer : MonoBehaviour
{

private void Start()
{
    Initialize();
}

#if UNITY_EDITOR
private void Initialize()
{
}

#elif !UNITY_EDITOR
DatagramSocket socket;

async void Initialize()
{
    socket = new DatagramSocket();
    socket.MessageReceived += Socket_MessageReceived;
    try
    {
        await socket.BindEndpointAsync(null, "1337");
    }
    catch (Exception e)
    {
        log += e.ToString() + "\n";
        log += SocketError.GetStatus(e.HResult).ToString() + "\n";
        return;
    }
}

private async void Socket_MessageReceived(Windows.Networking.Sockets.DatagramSocket sender,
    Windows.Networking.Sockets.DatagramSocketMessageReceivedEventArgs args)
{
    //...
}
#endif
}

我的日志中出现以下错误: “ System.UnauthorizedAccessException:访问被拒绝。” 和 “创建套接字需要至少一种网络功能。”

亲切的问候

0 个答案:

没有答案