How to use the mdns.tcp function in mdns

To help you get started, we’ve selected a few mdns examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github citelab / JAMScript / lib / jserver / mdnsregistration.js View on Github external
MDNSRegistrar.prototype.browse = function() {
    // the serice a node browses for depends on the type of the node
    /* create the browser */
    var browser;
    var self = this;
    if (this.machType === constants.globals.NodeType.DEVICE) {
        // devices browse for fogs
        browser = mdns.createBrowser(mdns.tcp(this.app + '-' + constants.globals.NodeType.FOG));
        browser.on('serviceUp', function(service) {
            /* emit the id, port, and IP address of the fog to the rest of the application */
            // possible that _getIp returns null
            var fogIp = self._getIp(service.addresses);
            if (fogIp === null) {
                // ignore the fog
                // TODO might want to modify this behavior
                return;
            }
            var retVal = {
                port: service.port, // int
                ip: fogIp, // string
                id: service.name // string
            };
            self.emit('fog-up', retVal);
        });
github AndreasMadsen / tcpnet / tcpnet.js View on Github external
if (IS_HEX_STRING.test(settings.uuid) === false) {
    throw new TypeError('service uuid must be a hex string');
  }

  // helps handling fast close
  this._closed = false;

  // Collection of online sockets
  this.connections = [];

  // Add connection handler if given
  if (connectionHandler) this.on('connection', connectionHandler);

  // Contains unique ID and a service key (given by service name)
  this._uuid = settings.uuid;
  this._key = mdns.tcp(settings.name);

  // Collection of services
  this._services = [];
  this._serviceBuffer = [];

  // Keeps addresses and port
  this._address = {
    addresses: null,
    port: null
  };

  // do the service listen on localhost
  this._internalAllowed = false;

  this._relayError = function (err) {
    self.emit('error', err);
github hongkongkiwi / node-apple-tv-remote / lib / server / RemoteServer.js View on Github external
bonjourClientService: 'touch-remote',
    bonjourTouchableServerService: 'touch-able',
    bonjourDACPServerService: 'dacp',
    guidLength: 16,
    persistGuids: true
  }, options);

  this.mdns_options = {
    name: 'Node Server',
    txtRecord: {
      DvTy: 'Node-Server',
      txtvers: '1',
    }};

  this.ads = [
    mdns.createAdvertisement(mdns.tcp(this.options.bonjourTouchableServerService), this.options.listenPort, this.mdns_options),
    mdns.createAdvertisement(mdns.tcp(this.options.bonjourDACPServerService), this.options.listenPort, this.mdns_options)
  ];

  this.app = express();

  this.browser = mdns.createBrowser(mdns.tcp(this.options.bonjourClientService));

  this.guids = {}; // Lets save/load this to disk
  this.sessionIds = {};
  this.lastSessionId = 0;

  // Add Command Routes
  require('./RemoteServerCommands')(this);
};
github fttx / barcode-to-pc-server / electron / main.js View on Github external
wsConnections.forEach(wsConnection => wsConnection.close());
        }
        bonjour.unpublishAll(() => {
            //bonjour.destroy()
        });

        if (mdnsAd) {
            mdnsAd.stop();
        }
    })


    try {
        var mdns = require('mdns');

        mdnsAd = mdns.createAdvertisement(mdns.tcp('http'), port, {
            name: 'Barcode to PC server - ' + getNumber()
        });
        mdnsAd.start();
    } catch (ex) {
        dialog.showMessageBox(mainWindow, {
            type: 'warning',
            title: 'Error',
            message: 'Apple Bonjour is missing.\nThe app may fail to detect automatically the server.\n\nTo remove this alert try to install Barcode to PC server again an reboot your system.',
        });

        var bonjourService = bonjour.publish({ name: 'Barcode to PC server - ' + getNumber(), type: 'http', port: port })

        bonjourService.on('error', err => { // err is never set?
            dialog.showMessageBox(mainWindow, {
                type: 'error',
                title: 'Error',
github well-knits / tomatotomato / server.js View on Github external
}).listen(function () {
  var ad = mdns.createAdvertisement(mdns.tcp('tomatotomato'), server.address().port)
    , msg = 'server running on ' + networkAddress() + ':' + server.address().port
  console.log(chalk.blue(msg))
  ad.start()
})
github spacebro / spacebro / index.js View on Github external
function _initBroadcast (config) {
  var ad = mdns.createAdvertisement(mdns.tcp(config.server.serviceName), config.server.port)
  ad.start()
}