Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NodeJS UDP Multicast How to

I'm trying to send a UDP Multicast Packet to: 230.185.192.108 so everyone subscribed will receive. A bit stuck. I believe it's broadcasting correctly, but can't seem to pick anything up with any client.

Server:

var news = [    "Borussia Dortmund wins German championship",    "Tornado warning for the Bay Area",    "More rain for the weekend",    "Android tablets take over the world",    "iPad2 sold out",    "Nation's rappers down to last two samples" ];  var dgram = require('dgram');  var server = dgram.createSocket("udp4");  server.bind(); server.setBroadcast(true) server.setMulticastTTL(128); server.addMembership('230.185.192.108');   setInterval(broadcastNew, 3000);  function broadcastNew() {     var message = new Buffer(news[Math.floor(Math.random()*news.length)]);     server.send(message, 0, message.length, 8088, "230.185.192.108");     console.log("Sent " + message + " to the wire...");     //server.close(); } 

Client

var PORT = 8088; var HOST = '192.168.0.102'; var dgram = require('dgram'); var client = dgram.createSocket('udp4');  client.on('listening', function () {     var address = client.address();     console.log('UDP Client listening on ' + address.address + ":" + address.port);     client.setBroadcast(true)     client.setMulticastTTL(128);      client.addMembership('230.185.192.108'); });  client.on('message', function (message, remote) {        console.log('A: Epic Command Received. Preparing Relay.');     console.log('B: From: ' + remote.address + ':' + remote.port +' - ' + message); });  client.bind(PORT, HOST); 

References More info on NodeJS Datagram

  • http://nodejs.org/api/dgram.html
like image 373
Taurian Avatar asked Jan 02 '13 22:01

Taurian


People also ask

How do I get UDP multicast?

To receive multicast datagrams sent to a particular port, bind to the local port, leaving the local address unspecified, such as INADDR_ANY. In this case, every incoming multicast or broadcast UDP datagram destined for the shared port is delivered to all sockets bound to the port.

What is Dgram in Nodejs?

The node:dgram module provides an implementation of UDP datagram sockets. import dgram from 'node:dgram'; const server = dgram. createSocket('udp4'); server. on('error', (err) => { console. log(`server error:\n${err.stack}`); server.

Is UDP used for multicast?

Unicast uses TCP (Transmission Control Protocol) for communications while multicast communication uses UDP (User Datagram Protocol).

What is UDP multicast address?

A multicast address is a logical identifier for a group of hosts in a computer network that are available to process datagrams or frames intended to be multicast for a designated network service.


1 Answers

Changed:

client.addMembership('230.185.192.108'); 

to

client.addMembership('230.185.192.108',HOST); //Local IP Address 
like image 170
Taurian Avatar answered Sep 28 '22 11:09

Taurian