Hello everyone.

We have decided to phase out the Mixed Reality Forums over the next few months in favor of other ways to connect with us.

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.

The plan between now and the beginning of May is to clean up old, unanswered questions that are no longer relevant. The forums will remain open and usable.

On May 1st we will be locking the forums to new posts and replies. They will remain available for another three months for the purposes of searching them, and then they will be closed altogether on August 1st.

So, where does that leave our awesome community to ask questions? Well, there are a few places we want to engage with you. 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. And always feel free to hit us up on Twitter @MxdRealityDev.

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.