How to use mdns - 10 common examples

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 DefinitelyTyped / DefinitelyTyped / mdns / mdns-tests.ts View on Github external
});

browser.start();

var r0 = mdns.tcp('http')                     // string form: _http._tcp
    , r1 = mdns.udp('osc', 'api-v1')            // string form: _osc._udp,_api-v1
    , r2 = new mdns.ServiceType('http', 'tcp')  // string form: _http._tcp
    , r3 = mdns.makeServiceType('https', 'tcp') // string form: _https._tcp
    ;

var txt_record = {
    name: 'bacon'
    , chunky: true
    , strips: 5
};
var ad:MDNS.Advertisement = mdns.createAdvertisement(mdns.tcp('http'), 4321, {txtRecord: txt_record});

var sequence = [
    mdns.rst.DNSServiceResolve()
    , mdns.rst.DNSServiceGetAddrInfo({families: [4] })
];

var browser = mdns.createBrowser(mdns.tcp('http'), {resolverSequence: sequence});

interface HammerTimeService extends MDNS.Service {
    hammerTime:Date;
}

function MCHammer(options:any) {
    options = options || {};
    return function MCHammer(service:HammerTimeService, next:()=>void) {
        console.log('STOP!');
github DefinitelyTyped / DefinitelyTyped / mdns / mdns-tests.ts View on Github external
var browser = mdns.createBrowser(mdns.tcp('http'));

browser.on('serviceUp', function(service:MDNS.Service) {
    console.log("service up: ", service);
});
browser.on('serviceDown', function(service:MDNS.Service) {
    console.log("service down: ", service);
});

browser.start();

var r0 = mdns.tcp('http')                     // string form: _http._tcp
    , r1 = mdns.udp('osc', 'api-v1')            // string form: _osc._udp,_api-v1
    , r2 = new mdns.ServiceType('http', 'tcp')  // string form: _http._tcp
    , r3 = mdns.makeServiceType('https', 'tcp') // string form: _https._tcp
    ;

var txt_record = {
    name: 'bacon'
    , chunky: true
    , strips: 5
};
var ad:MDNS.Advertisement = mdns.createAdvertisement(mdns.tcp('http'), 4321, {txtRecord: txt_record});

var sequence = [
    mdns.rst.DNSServiceResolve()
    , mdns.rst.DNSServiceGetAddrInfo({families: [4] })
];

var browser = mdns.createBrowser(mdns.tcp('http'), {resolverSequence: sequence});
github DefinitelyTyped / DefinitelyTyped / mdns / mdns-tests.ts View on Github external
ad.start();

var browser = mdns.createBrowser(mdns.tcp('http'));

browser.on('serviceUp', function(service:MDNS.Service) {
    console.log("service up: ", service);
});
browser.on('serviceDown', function(service:MDNS.Service) {
    console.log("service down: ", service);
});

browser.start();

var r0 = mdns.tcp('http')                     // string form: _http._tcp
    , r1 = mdns.udp('osc', 'api-v1')            // string form: _osc._udp,_api-v1
    , r2 = new mdns.ServiceType('http', 'tcp')  // string form: _http._tcp
    , r3 = mdns.makeServiceType('https', 'tcp') // string form: _https._tcp
    ;

var txt_record = {
    name: 'bacon'
    , chunky: true
    , strips: 5
};
var ad:MDNS.Advertisement = mdns.createAdvertisement(mdns.tcp('http'), 4321, {txtRecord: txt_record});

var sequence = [
    mdns.rst.DNSServiceResolve()
    , mdns.rst.DNSServiceGetAddrInfo({families: [4] })
];
github AndreasMadsen / tcpnet / test / simple / loopback-interface.js View on Github external
var tcpnet = require('../../tcpnet.js');
var test = require('tap').test;
var async = require('async');
var ifname = require('interface-name');
var mdns = require('mdns');

// Avahi system is expected to emit an error
if (mdns.isAvahi) {
  test('avahi system should emit error', function (t) {

    var serviceA = tcpnet('test-service');
        serviceA.listen(0, '127.0.0.1');

        serviceA.once('error', function (err) {
          t.equal(
            err.message,
            'loopback address is not supported on linux-avahi platform'
          );

          serviceA.close(function () {
            t.end();
          });
        });
  });
github DefinitelyTyped / DefinitelyTyped / mdns / mdns-tests.ts View on Github external
ad.start();

var browser = mdns.createBrowser(mdns.tcp('http'));

browser.on('serviceUp', function(service:MDNS.Service) {
    console.log("service up: ", service);
});
browser.on('serviceDown', function(service:MDNS.Service) {
    console.log("service down: ", service);
});

browser.start();

var r0 = mdns.tcp('http')                     // string form: _http._tcp
    , r1 = mdns.udp('osc', 'api-v1')            // string form: _osc._udp,_api-v1
    , r2 = new mdns.ServiceType('http', 'tcp')  // string form: _http._tcp
    , r3 = mdns.makeServiceType('https', 'tcp') // string form: _https._tcp
    ;

var txt_record = {
    name: 'bacon'
    , chunky: true
    , strips: 5
};
var ad:MDNS.Advertisement = mdns.createAdvertisement(mdns.tcp('http'), 4321, {txtRecord: txt_record});

var sequence = [
    mdns.rst.DNSServiceResolve()
    , mdns.rst.DNSServiceGetAddrInfo({families: [4] })
];

var browser = mdns.createBrowser(mdns.tcp('http'), {resolverSequence: sequence});
github gibber-cc / gibber / js / node / control.js View on Github external
}
	        }
	    }
	}
	console.log("MY IP = ", myIP);
	return addresses[0];
})();

// can't have double quotes sent to Control... double quotes are the default for JSON stringify
function stringify(string) {
	var s = JSON.stringify(string);
	s = s.replace(/\"/g, "'");
	return s;
}

var browser = mdns.createBrowser(mdns.udp('osc'));

browser.on('serviceUp', function(service) {
	console.log(service);
	control = new osc.UdpSender(service.host, 8080);
	control.send( '/control/createBlankInterface', 'ss', ['testing', 'portrait'] );
	control.send( "/control/pushDestination", 's', [myIP + ":" + 8081] );	
});

browser.on('serviceDown', function(service) { console.log("service down: ", service); });
browser.start();

var receiver = new osc.UdpReceiver(8081);
receiver.on('', function(e) {
	console.log(e);
	gibber.emit('OSC', {path:e.path, tags:e.typetag, params:e.params});
});
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 gebhardm / energyhacks / Gauge / serve_mqtt.js View on Github external
var url = require("url");

var path = require("path");

var io = require("socket.io")(http);

// multicast DNS service discovery
var mdns = require("mdns");

// resolution requence added due to mdns issue - see https://github.com/agnat/node_mdns/issues/130
var sequence = [ mdns.rst.DNSServiceResolve(), "DNSServiceGetAddrInfo" in mdns.dns_sd ? mdns.rst.DNSServiceGetAddrInfo() : mdns.rst.getaddrinfo({
    families: [ 4 ]
}), mdns.rst.makeAddressesUnique() ];

// detect mqtt publishers and create corresponding servers
var mdnsbrowser = mdns.createBrowser(mdns.tcp("mqtt"), {
    resolverSequence: sequence
});

mdnsbrowser.on("serviceUp", function(service) {
    console.log("Detected MQTT service on: " + service.addresses[0] + ":" + service.port);
    mqttconnect(service.addresses[0], service.port);
});

mdnsbrowser.on("serviceDown", function(service) {
    console.log("MQTT service down: ", service);
});

mdnsbrowser.on("error", function(exception) {
    console.log("An error occured: ", exception);
});
github citelab / JAMScript / lib / jdiscovery / mdnsregistry.js View on Github external
MDNSRegistry.prototype._browse = function(self, attr, machType, event) {
    var browser = mdns.createBrowser(mdns.tcp(self.app + '-' + machType[0] + '-' + attr));

    self.browsers[machType][attr] = browser;

    browser.on('serviceUp', function(service) {
        // ignore our own services
        if (service.name == self.id) {
            return;
        }

        // emit a discovery event!
        self.emit('discovery', attr, event, service.name, JSON.parse(service.txtRecord.msg).payload);
    });

    browser.on('error', function(err) {
        browser.stop();
        self.emit('browser-error', self, attr, machType, event);