Socket
Book a DemoInstallSign in
Socket

dgram-broadcast

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dgram-broadcast

A more obvious interface for local UDP broadcast

1.0.0
latest
Source
npmnpm
Version published
Weekly downloads
14
250%
Maintainers
1
Weekly downloads
 
Created
Source

dgram-broadcast

A more obvious dgram broadcast.

dgram-broadcast has the correct defaults to just work for broadcast on your local area network.

Example

Broadcast on port 8999 on your local area network.

const createStream = require('dgram-broadcast')

const stream = createStream(8999)

stream.on('data', (msg) => {
  console.log(msg.toString())
  console.log(msg.address, msg.port, msg.echo)
})

setInterval(() => {
  stream.write(Buffer.from(new Date().toString(), 'utf8'))
}, 1000)

API

stream = createStream(port, loopback=true, dest=['255.255.255.255'])

Stream on the port port. If loopbackis false, do not output your own messages. Returns a Node.js stream.destis an array of all the destination addresses on which to broadcast, by default it has only255.255.255.255` as the destination.

stream.on('data', (msg) => { ... })

msg is the message as a buffer, it also has msg.address and msg.port set to the address and port that originated the message. If msg is a message that this stream sent, it will also have msg.loopback = true.

Back-pressure

UDP does not have back-pressure, but the stream API in this module does. If the stream is paused, it will just drop messages. If when the stream is resumed, it will emit the latest message.

License

MIT

FAQs

Package last updated on 25 Jan 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.