4

I called dgram.setBroadcast(flag) and it returned a not yet implemented error on Node.js version v0.6.3.

Does Node.js still support UDP broadcasting?

Edit: I found some discussions said that broadcast was removed in 0.5.x and probably be back in the future.

still not yet implemented in v0.6.6

I tried 0.6.10 in windows 7 x64, the multicast did not work yet.

var dgram = require('dgram'); 
var PACKET_LEN = 64; 
var message = new Buffer(PACKET_LEN); 
var client = dgram.createSocket("udp4"); 
client.setMulticastTTL(128); 
//dgram.addMembership(multicastAddress, [multicastInterface]) 
client.addMembership('234.18.128.10', "172.18.128.64") ; 
// dgram.send(buf, offset, length, port, address, [callback]) 
client.send(message, 0, PACKET_LEN, 7000, "234.18.128.10"); 
client.close(); 

I got an "Error: addMembership EADDRNOTAVAIL".

after ref here: https://github.com/joyent/node/blob/master/test/simple/test-dgram-multicast-multi-process.js , I finally make multicast work on my windows pc.
node ver=0.6.19

var dgram = require('dgram'); 
var message = new Buffer('this is my message'); 

var client = dgram.createSocket("udp4"); 
client.bind();
client.setBroadcast(true)
client.setMulticastTTL(128); 
client.send(message, 0, message.length, 5007, "224.1.1.1"); 
client.close();
holly
  • 577
  • 1
  • 5
  • 12
  • Well in the discussion says that it will be back in v0.6.4 or v0.6.5. Version 0.6.4 is due to 3 days, and probably one more week for 0.6.5. – Farid Nouri Neshat Nov 29 '11 at 13:23

1 Answers1

6

Today's your lucky day: Datagram support was reintroduced in nodejs 0.6.9.

http://blog.nodejs.org/2012/01/27/node-v0-6-9/

timoxley
  • 5,156
  • 3
  • 36
  • 40
  • And in windows version 0.6.10 I can't send multicast successfully too :-(, although it's changelog said it can. – holly Feb 14 '12 at 05:42
  • To timoxley: var dgram = require('dgram'); var PACKET_LEN = 64; var message = new Buffer(PACKET_LEN); var client = dgram.createSocket("udp4"); client.setMulticastTTL(128); //dgram.addMembership(multicastAddress, [multicastInterface]) client.addMembership('234.18.128.10', "172.18.128.64") ; // dgram.send(buf, offset, length, port, address, [callback]) client.send(message, 0, PACKET_LEN, 7000, "234.18.128.10"); client.close(); I got an "Error: addMembership EADDRNOTAVAIL". – holly Feb 16 '12 at 03:09
  • sorry for the terrible formatting. I added the code to the question. – holly Feb 17 '12 at 02:19