Networking 无法在HoloLens服务器上接收HTTP消息
几天来,我一直在尝试在HoloLens上实现一个简单的服务器,以接收从本地网络上的智能对象发送的HTTP数据包 到目前为止,我的代码如下(我只报告在HoloLens上实际运行的部分代码):` 服务器正确启动,但当我尝试从智能对象发送数据包时,不会触发Listener_ConnectionReceived() 我已经在应用程序清单上设置了PrivateNetworkClientServer功能 有什么不对劲吗?Networking 无法在HoloLens服务器上接收HTTP消息,networking,server,hololens,Networking,Server,Hololens,几天来,我一直在尝试在HoloLens上实现一个简单的服务器,以接收从本地网络上的智能对象发送的HTTP数据包 到目前为止,我的代码如下(我只报告在HoloLens上实际运行的部分代码):` 服务器正确启动,但当我尝试从智能对象发送数据包时,不会触发Listener_ConnectionReceived() 我已经在应用程序清单上设置了PrivateNetworkClientServer功能 有什么不对劲吗? 提前谢谢你 你能试着调试它看看是否抛出了异常吗?没有抛出异常,它只是不调用该方法。你能
提前谢谢你 你能试着调试它看看是否抛出了异常吗?没有抛出异常,它只是不调用该方法。你能试着将
initializewpserver
方法公开吗?是的,但我添加了一些日志,似乎initializewpserver的所有行都被执行了。
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
using UnityEngine.Networking;
using System.Net.Sockets;
using System.Net;
using System.Threading;
using System.Text;
using UnityEngine.UI;
#if !UNITY_EDITOR
using Windows.Networking;
using Windows.Networking.Sockets;
using Windows.Storage.Streams;
using Windows.Networking.Connectivity;
#endif
public class DolphinManager : MonoBehaviour
{
private static string holoLensIpAddr = "192.168.0.147";
private static int holoLensPort = 12345;
#if UNITY_EDITOR
private HttpListener _listener;
#endif
#if !UNITY_EDITOR
private StreamReader reader;
private StreamSocketListener listener;
#endif
void Start()
{
#if UNITY_EDITOR
Invoke("InitializeUnityServer", 4f);
#else
Invoke("InitializeUWPServer", 4f);
#endif
}
#if !UNITY_EDITOR
private async void InitializeUWPServer()
{
try
{
listener = new StreamSocketListener();
serverHost = new Windows.Networking.HostName(anyIp);
listener.ConnectionReceived += Listener_ConnectionReceived;
listener.Control.KeepAlive = false;
await listener.BindServiceNameAsync(holoLensPort.ToString());
} catch(Exception e) { Debug.Log(e.Message); }
}
#endif
#if !UNITY_EDITOR
private async void Listener_ConnectionReceived(StreamSocketListener sender, StreamSocketListenerConnectionReceivedEventArgs args)
{
Debug.log("message received!");
}