cannot receive HTTP messages on HoloLens server

i've been trying for days to implement a simple server on HoloLens to receive HTTP packets sent from a smart object on a local network.

My code so far is the following (i report only the part of the code that actually runs on HoloLens):`

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!");
        }

The server starts correctly, but when i try to send a packet from my smart object, Listener_ConnectionReceived() is not triggered.

I have already set the PrivateNetworkClientServer capability on the app manifest.

What could be wrong? Thank you in advance!

Sign In or Register to comment.