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

Socket.IO NodeJS not working in HoloLens

PeriPeri
edited September 2018 in Questions And Answers

I have implementing sockets in hololens app. App is working fine when run in Unity editor. But not working on hololens. Sample code below:

 public SocketManager Manager;

        void ConnectSocket()
        {
             SocketOptions options = new SocketOptions();
                    options.AutoConnect = false;
                    Manager = new SocketManager(new Uri("http://holo.us.openode.io/socket.io/"), options);
                    // The argument will be an Error object.
                    Manager.Socket.On(SocketIOEventTypes.Error, (socket, packet, args) => Debug.LogError(string.Format("Error: {0}", args[0].ToString())));
                    Manager.GetSocket("/");

                    Manager.Socket.On("joinroom", OnJoinedRoom);
                    Manager.Socket.On("sendchat", OnFirstMessageRecieved);
                    Manager.Open();
                    Manager.Socket.Emit("adduser", 11, "User001");
         }           
          private void OnJoinedRoom(Socket socket, Packet packet, object[] args)
          {
            Debug.Log("Received message from server");
          }
          private void OnFirstMessageRecieved(Socket socket, Packet packet, object[] args)
          {
             Debug.Log("Receive...");
           }

NodeJS Server Code:

    io.sockets.on('connection', function (socket) {

        // when the client emits 'adduser', this listens and executes
        socket.on('adduser', function (username,roomid) {
            // store the username in the socket session for this client
            socket.username = username;
            // store the room name in the socket session for this client
            socket.room = roomid;

            // add the client's username to the global list
            usernames[username] = username;
            // send client to room 1
            socket.join(roomid);
            // echo to client they've connected
            socket.emit('joinroom', 'SERVER', 'you have connected to ' + roomid,username);
            console.log('User : '+username+'connected to room : ' + roomid);
            // echo to room 1 that a person has connected to their room
            socket.broadcast.to(roomid).emit('newuserjoined', 'SERVER', username + ' has connected to this room ' + roomid);
            socket.emit('updaterooms', rooms, roomid);
        });

        // when the client emits 'sendchat', this listens and executes
        socket.on('sendchat', function (data) {
            // we tell the client to execute 'updatechat' with 2 parameters
            io.sockets.in(socket.room).emit('updatechat', socket.username, data);
        });

    server.listen(app.get('port'),function(){
    console.log("Server is running...");
    });

Note: Enabled InternetClientServer And PrivateNetworkClientServer.
Unity version: Unity 2017.2.2p1

Used BestHttp unity asset to implement socket.io(https://assetstore.unity.com/packages/tools/network/best-http-10872).

Comments

Sign In or Register to comment.