Hello everyone.

The Mixed Reality Forums here are no longer being used or maintained.

There are a few other places we would like to direct you to for support, both from Microsoft and from the community.

The first way we want to connect with you is our mixed reality developer program, which you can sign up for at https://aka.ms/IWantMR.

For technical questions, please use Stack Overflow, and tag your questions using either hololens or windows-mixed-reality.

If you want to join in discussions, please do so in the HoloDevelopers Slack, which you can join by going to https://aka.ms/holodevelopers, or in our Microsoft Tech Communities forums at https://techcommunity.microsoft.com/t5/mixed-reality/ct-p/MicrosoftMixedReality.

And always feel free to hit us up on Twitter @MxdRealityDev.
Options

Help with UDP problem

edited August 2017 in Questions And Answers

I'm just trying to get some sort of code to work that can read in information from a UDP source to Hololens, and I can't seem to be getting through. I'm using this code and Packet Sender to test, but I don't see any results. Is my changing the boolean value in the event and letting the Update loop change my textmesh not allowed? I'm drawing a bit of a blank here.

Note, this represents all the code as it is.

`using UnityEngine;
using System;
using System.IO;

if !UNITY_EDITOR

using Windows.Networking.Sockets;

endif

public class UDPListen : MonoBehaviour
{
public TextMesh test;
public string port;
//public string word;
public bool rec;

if !UNITY_EDITOR

DatagramSocket socket;
// use this for initialization
async void Start()
{

    Debug.Log("Waiting for a connection...");

    socket = new DatagramSocket();
    socket.MessageReceived += Socket_MessageReceived;

    try
    {
        await socket.BindEndpointAsync(null , port);
    }
    catch (Exception e)
    {
        Debug.Log(e.ToString());
        Debug.Log(SocketError.GetStatus(e.HResult).ToString());
        return;
    }

    Debug.Log("exit start");

}

endif

// Update is called once per frame
void Update()
{
    if (rec)
    {
        test.text = "worked";
    }
}

if !UNITY_EDITOR

private async void Socket_MessageReceived(Windows.Networking.Sockets.DatagramSocket sender,
    Windows.Networking.Sockets.DatagramSocketMessageReceivedEventArgs args)
{
    //Read the message that was received from the UDP echo client.
    Stream streamIn = args.GetDataStream().AsStreamForRead();
    StreamReader reader = new StreamReader(streamIn);
    string message = await reader.ReadLineAsync();
    rec = true;
    //word = message;
    Debug.Log("MESSAGE: " + message);
}

endif

}`

Sign In or Register to comment.