Projekt

Obecné

Profil

Stáhnout (788 Bajtů) Statistiky
| Větev: | Revize:
1 3a515b92 cagy
var mdns = require('./')()
2
3
mdns.on('warning', function (err) {
4
  console.log(err.stack)
5
})
6
7
mdns.on('response', function (response) {
8
  console.log('got a response packet:', response)
9
})
10
11
mdns.on('query', function (query) {
12
  console.log('got a query packet:', query)
13
14
  // iterate over all questions to check if we should respond
15
  query.questions.forEach(function (q) {
16
    if (q.type === 'A' && q.name === 'example.local') {
17
      // send an A-record response for example.local
18
      mdns.respond({
19
        answers: [{
20
          name: 'example.local',
21
          type: 'A',
22
          ttl: 300,
23
          data: '192.168.1.5'
24
        }]
25
      })
26
    }
27
  })
28
})
29
30
// lets query for an A-record for example.local
31
mdns.query({
32
  questions: [{
33
    name: 'example.local',
34
    type: 'A'
35
  }]
36
})