https://github.com/derhuerst/multicast-channel
A simple communication channel using UDP multicast.
https://github.com/derhuerst/multicast-channel
multicast udp
Last synced: 3 months ago
JSON representation
A simple communication channel using UDP multicast.
- Host: GitHub
- URL: https://github.com/derhuerst/multicast-channel
- Owner: derhuerst
- License: isc
- Created: 2017-08-03T13:34:55.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-08-03T14:55:34.000Z (almost 9 years ago)
- Last Synced: 2025-02-07T23:48:25.925Z (over 1 year ago)
- Topics: multicast, udp
- Language: JavaScript
- Homepage: https://github.com/derhuerst/multicast-channel
- Size: 5.86 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license.md
Awesome Lists containing this project
README
# multicast-channel
**A simple communication channel using [UDP](https://en.wikipedia.org/wiki/User_Datagram_Protocol) [multicast](https://en.wikipedia.org/wiki/IP_multicast).** Node.js only. Send an receive anything `JSON.stringify`-able.
Similar to [`multicast`](https://github.com/ForbesLindesay-Unmaintained/multicast). The code is heavily inspired by [`multicast-dns`](https://github.com/mafintosh/multicast-dns).
[](https://www.npmjs.com/package/multicast-channel)
[](https://travis-ci.org/derhuerst/multicast-channel)

[](https://gitter.im/derhuerst)
## Installing
```shell
npm install multicast-channel
```
## Usage
```js
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!'})
})
```
## API
```js
createChannel([opt])
```
`opt` may have the following keys:
- `name`: The user name to send messages with.
- `pack(content, from)`: Pack a message into a [`Buffer`](https://nodejs.org/api/buffer.html).
- `unpack(buf)`: Unpack a message from a [`Buffer`](https://nodejs.org/api/buffer.html). Should return an object with `content` and `from`.
## Contributing
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](https://github.com/derhuerst/multicast-channel/issues).