简体   繁体   中英

How do get ILPIP (PIP) from within a Node.JS application running ona VM in Azure?

I need to get the DNS name (ILPIP DNS name) in a Node.JS application (an IoT gateway) that is running on a VM in Azure.

Background details. I need this so the application can inform the web frontend where to open the socket.io connection to when the web based client wish to communicate with the IoT gateway.

I have been looking in Microsofts Azure modules for Node.JS but I haven't found anything that gives the ILPIP (assigned dns name)

You can try to use RoleEnvironment.getCurrentRoleInstance() function in Azure SDK for Node.js, run the following code snippet in a classic VM:

var azure = require('azure');
 azure.RoleEnvironment.getCurrentRoleInstance(function (error, instance) {
     if (!error && instance['endpoints']) {
         //You can get information about "endpoint1" such as its address and port via
         console.log(instance)
     } else {
         console.log(error);
     }
 });

You may get the following similar info of role instance:

{ id: 'WorkerRole1_IN_0',
  roleName: 'WorkerRole1',
  faultDomain: '0',
  updateDomain: '0',
  endpoints: 
   { 'Microsoft.WindowsAzure.Plugins.RemoteAccess.Rdp': 
      { name: 'Microsoft.WindowsAzure.Plugins.RemoteAccess.Rdp',
        address: '100.104.92.19',
        port: '3389',
        publicPort: '0',
        protocol: 'tcp',
        roleInstanceId: 'WorkerRole1_IN_0' },
     'Microsoft.WindowsAzure.Plugins.RemoteForwarder.RdpInput': 
      { name: 'Microsoft.WindowsAzure.Plugins.RemoteForwarder.RdpInput',
        address: '100.104.92.19',
        port: '20000',
        publicPort: '3389',
        protocol: 'tcp',
        roleInstanceId: 'WorkerRole1_IN_0' } 
    } 
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM