Why doesn't Node.js UDP client receive messages? -


i'm trying write multicast dns client in node.js .

the goal show same logical output of running:

% dns-sd -g v4 irkitd2a8.local date: ---thu 20 mar 2014--- 20:38:21.426  ...starting... timestamp     a/r flags if hostname                               address                                      ttl 20:38:22.571  add     2  4 irkitd2a8.local.                       192.168.1.43                                 10 

this udp packets under hood:

% sudo tcpdump -n udp port 5353 tcpdump: data link type pktap tcpdump: verbose output suppressed, use -v or -vv full protocol decode listening on pktap, link-type pktap (packet tap), capture size 65535 bytes 20:38:22.450804 ip 192.168.1.37.5353 > 224.0.0.251.5353: 0 (qu)? irkitd2a8.local. (33) 20:38:22.571411 ip 192.168.1.43.5353 > 192.168.1.37.5353: 0*- [0q] 1/0/0 192.168.1.43 (43) 

so wrote this:

var port            = 5353; var multicast_group = "224.0.0.251";  var dgram = require("dgram");  var client = dgram.createsocket("udp4"); var name = "irkitd2a8";  var payload = new buffer(     [].concat( [ 0x00, 0x00, // id                  0x00, 0x00, // fixed                  0x00, 0x01, // qdcount: number of entries in question section                  0x00, 0x00,                  0x00, 0x00,                  0x00, 0x00                ],                name.length,                name.split("").map( function(letter) {                    return letter.charcodeat(0);                }),                "local".length,                "local".split("").map( function(letter) {                    return letter.charcodeat(0);                }),                0x00, // null terminate                [ 0x00, 0x01, // qtype                  0x80, 0x01  // qclass                  // http://tools.ietf.org/html/draft-cheshire-dnsext-multicastdns-06#section-6.5                  // multicast dns defines top bit in class field of dns question "unicast response" bit.                ]              ) ); client.on("message", function(message, rinfo) {     console.log("received: ",message,rinfo); }); client.on("listening", function() {     console.log("listening on ",client.address());      client.setbroadcast(true);     client.setttl(64);     client.setmulticastttl(64);     client.setmulticastloopback(true);     client.addmembership(multicast_group);     client.send(payload, 0, payload.length, port, multicast_group, function(err,bytes) {         console.log("err: "+err+" bytes: "+bytes);         // client.close();     }); }); client.on("close", function() {     console.log("closed"); }); client.on("error", function(err) {     console.log("error: ",err); }); client.bind(5353); 

when running script, outputs:

% node client.js listening on  { address: '0.0.0.0', family: 'ipv4', port: 5353 } err: null bytes: 33 

and tcpdump outputs same thing:

% sudo tcpdump -n udp port 5353 tcpdump: data link type pktap tcpdump: verbose output suppressed, use -v or -vv full protocol decode listening on pktap, link-type pktap (packet tap), capture size 65535 bytes 20:48:33.816076 ip 192.168.1.37.5353 > 224.0.0.251.5353: 0 (qu)? irkitd2a8.local. (33) 20:48:33.853892 ip 192.168.1.43.5353 > 192.168.1.37.5353: 0*- [0q] 1/0/0 192.168.1.43 (43) 

so looks it's correctly sending same packets dns-sd does, , receiving same thing, script's message event handler doesn't fire. why? how fix , output packets received?

i'm on macosx10.9, node.js 0.10.25

firewall.

i did:

  1. there several entries named node in processes list in system preferences > security & privacy > firewall, removed node entries.
  2. reboot macosx
  3. restart script
  4. a dialog appeared ask if approve node listening connections, approved.
  5. problem solved!

sorry guys.


Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -