A simple communication channel using UDP multicast. Node.js only. Send an receive anything JSON.stringify
-able.
Similar to multicast
. The code is heavily inspired by multicast-dns
.
npm install multicast-channel
const createChannel = require('multicast-channel')
const channel = createChannel({name: 'derhuerst'})
channel.on('error', console.error)
channel.on('message', (msg, from) => {
console.log('got a message!', msg, from)
})
channel.on('open', () => {
channel.send({hello: 'friends!'})
})
createChannel([opt])
opt
may have the following keys:
name
: The user name to send messages with.pack(content, from)
: Pack a message into aBuffer
.unpack(buf)
: Unpack a message from aBuffer
. Should return an object withcontent
andfrom
.
If you have a question or have difficulties using multicast-channel
, please double-check your code and setup first. If you think you have found a bug or want to propose a feature, refer to the issues page.