Socket.IO NodeJS not working in HoloLens

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(""), 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.Socket.On("joinroom", OnJoinedRoom);
                    Manager.Socket.On("sendchat", OnFirstMessageRecieved);
                    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)

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
   = roomid;

            // add the client's username to the global list
            usernames[username] = username;
            // send client to room 1
            // 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
  '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
  'updatechat', socket.username, data);

    console.log("Server is running...");

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

Used BestHttp unity asset to implement


Sign In or Register to comment.