javascript - Why does my Node.js script not see any UDP packets that are being sent on a specific port? -
i have c# app sends udp packets specific ip , port , works well, because have other app receives packages. send them can display on webpage - i've read node.js fit here.
i installed current version of node.js under windows environment , took following code:
var port = 19777; var multicast_group = "224.0.0.251"; var dgram = require("dgram"); var client = dgram.createsocket("udp4"); 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(19777);
and started sending packets on following ip "224.0.0.251"
, port 19777
c# app - however, after runnint client app i've got following error:
c:\users\user\desktop>node client.js error: { [error: bind eaddrinuse] code: 'eaddrinuse', errno: 'eaddrinuse', sysc all: 'bind' }
what doing wrong? , - after fixing issue - able see packets in console? thanks.
------------- edit:
following advice of john, modified app node.js listening on port. made progress , on output of console get:
c:\users\user\desktop>node client.js listening on { address: '0.0.0.0', family: 'ipv4', port: 19777 } c:\users\user\desktop\client.js:19 client.send(payload, 0, payload.length, port, multicast_group, function(er ^ referenceerror: payload not defined @ socket.<anonymous> (c:\users\godyckim\desktop\client.js:19:17) @ socket.emit (events.js:104:17) @ startlistening (dgram.js:139:10) @ dgram.js:230:7 @ dns.js:85:18 @ process._tickcallback (node.js:355:11) @ function.module.runmain (module.js:503:11) @ startup (node.js:129:16) @ node.js:814:3
but still no packets visible.. ok, see didn't define payload variable... want achieve receive packets sent udp , either display in node.js console (that start me), or transfer further can see them in browser. in second case - i'm doing wrong now? thanks!
Comments
Post a Comment