Navigation Menu

Skip to content

Commit

Permalink
added some more tutorial text
Browse files Browse the repository at this point in the history
  • Loading branch information
agnat committed Aug 30, 2010
1 parent f94e9ce commit d44dd2e
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions README.textile
Expand Up @@ -4,10 +4,10 @@ node_mdns adds support for multicast DNS service discovery, also known as zeroco

Internally, it uses the mDNSResponder API which is available on all major platforms.

h2. Build, Installation and Dependencies

On Linux and other systems using the avahi daemon the avahi dns_sd compat library and its header files are required.

h2. Installation

node_mdns is available as a npm package. To fetch, compile and install the add-on do:

bc. npm install mdns
Expand All @@ -20,7 +20,34 @@ node-waf configure build && ./run_tests

h2. Tutorial

Multicast DNS service discovery provides a way to announce and discover services on the local network.
Multicast DNS service discovery provides a way to announce and discover services on the local network. Here is how to announce a HTTP server running on port 4321:

bc.. var mdns = require('mdns');
var ad = mdns.createAdvertisement('http', 4321);
ad.start();

And here is how to browse all HTTP servers on the local network:

bc.. var browser = mdns.createBrowser('http');
browser.on('serviceUp', function(info, flags) {
sys.puts("Up: " + sys.inspect(info));
});
browser.on('serviceDown', function(info, flags) {
sys.puts("Down: " + sys.inspect(info));
});
browser.start();

As you can see the browser object is an EventEmitter. For each HTTP server a 'serviceUp' event is emitted. Likewise, if a server disappears 'serviceDown' is send. A 'serviceUp' info object might look like this:

bc.. { interfaceIndex: 4
, serviceName: 'somehost'
, regtype: '_http._tcp.'
, replyDomain: 'local.'
, fullname: 'somehost._http._tcp.local.'
, host: 'somehost.local.'
, port: 4321
, addresses: [ '10.1.1.50', 'fe80::21f:5bff:fecd:ce64' ]
}

h2. Reference

Expand Down

0 comments on commit d44dd2e

Please sign in to comment.