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

Cannot connect HoloLens to server

I am trying to connect HoloLens to server to send data from HoloLens to the server.

For the server, I created a Console Application in Visual Studio and followed the example here:
Asynchronous Server Socket Example

From the HoloLens side:

public class SendSocketStreamClient {
    // The port number for the remote device.  
    private int port;
    private string serverIP;

    public SendSocketStreamClient(int portNum, string ip){
        port = portNum;
        serverIP = ip;
    }

#if !UNITY_EDITOR && UNITY_METRO
    private StreamSocket networkConnection;

    // The response from the remote device.  
    private static String response = String.Empty;

    public void StartClient()
    {
        // Setup a connection to the server.
        HostName networkHost = new HostName(serverIP);
        networkConnection = new StreamSocket();

        IAsyncAction outstandingAction = networkConnection.ConnectAsync(networkHost, port.ToString());
        AsyncActionCompletedHandler aach = new AsyncActionCompletedHandler(NetworkConnectedHandler);
        outstandingAction.Completed = aach;
    }

    public void NetworkConnectedHandler(IAsyncAction asyncInfo, AsyncStatus status)
    {
        // Status completed is successful.
        if (status == AsyncStatus.Completed)
        {
            DataWriter networkDataWriter;

            // Since we are connected, we can send the data we set aside when establishing the connection.
            using (networkDataWriter = new DataWriter(networkConnection.OutputStream))
            {

                networkDataWriter.WriteBytes(Encoding.ASCII.GetBytes("Sending Trial 1"));

                // Again, this is an async operation, so we'll set a callback.
                DataWriterStoreOperation dswo = networkDataWriter.StoreAsync();
                dswo.Completed = new AsyncOperationCompletedHandler<uint>(DataSentHandler);
            }
        }
        else
        {
            // TODO resend
            Debug.Log("Failed to establish connection. Error Code: " + asyncInfo.ErrorCode);
            networkConnection.Dispose();
        }
    }

    public void DataSentHandler(IAsyncOperation<uint> operation, AsyncStatus status)
    {
        if (status == AsyncStatus.Error)
        {
            // didn't send, so requeue
            Debug.Log("Error while sending " + operation.ErrorCode);
        }
        // Always disconnect here since we will reconnect when sending the next mesh.  
        networkConnection.Dispose();
    }
#endif
}

I then call this class in a c# script by:

#if !UNITY_EDITOR && UNITY_METRO
        SendSocketStreamClient newClient = new SendSocketStreamClient(ConnectionPort, ServerIP.Trim());
        newClient.StartClient();
#endif

However, I always get the error below.

Failed to establish connection. Error Code: System.Runtime.InteropServices.COMException (0x8007274D): No connection could be made because the target machine actively refused it.

Any idea what am doing wrong or how to send data from HoloLens to server? Is there something wrong with the server?

Thank you.

Answers

Sign In or Register to comment.