Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Find and communicate with network nodes over UDP.
udp-node provides a programatic way of discovering and interacting with other
nodes over UDP. This interaction can be easily achieved using provided methods,
like ping
, broadcast
and onNode
and you can also create your custom events
using the on
and send
methods.
npm install --save udp-node
In the sample
folder you'll find the basics of finding nodes and sending custom messages.
The code is prepared to run on the same machine by changing default port on one node.
In this example we will send a broadcast message to find all nodes in the network. These nodes are other instances of udp-node.
const UdpNode = require('udp-node')
const six = new UdpNode()
six
.set({
name: 'Six',
type: 'machine'
})
.broadcast()
.onNode((message, rinfo) => {
// FOUND NODE
// message: contains node's name, type and other details set when node was initialized using set()
// rinfo: contains node's ip address and port
})
This broadcast message is sent to the default port, 3024. Nodes listening on that port will automatically answer with a pong message.
When a node is created it can set a type. Then, you can send a broadcast message filtering by type. Nodes belonging to that type are the only ones who will answer with a pong.
const UdpNode = require('udp-node')
const six = new UdpNode()
six
.set({
name: 'Six',
type: 'machine'
})
.broadcast({
filter: ['human']
})
.onNode((message, rinfo) => {
// FOUND HUMAN NODE
})
A guid is automatically set for each node when the node is constructed.
This means that it will change each time you do new UdpNode()
.
Initializes udp-node. Must be called to start udp client.
Params object:
Sends a broadcast message to the network. Other udp-nodes will respond with a pong message containing their identity.
Params object:
Sends a ping message to a specific udp-node. If that node is available it will respond with a pong message containing its identity.
Params object:
Sends a custom message.
message
properties:
After the message is sent passed callback is called.
Called when a node of interest if found, either by a response to our broadcast or ping or when the other node send us a broadcast or ping.
Adds a listener for a custom message. When a message of the specified type is recieved calls the passed callback.
CHANGE from previous version:
Returns a ref to this
to allow chaining.
Params:
Turns off individual listeners or all listeners for passed message type when index is not provided.
Params:
udp-node uses Winston for logging. Please, refer to logging levels on the official documentation for more details.
Params:
Closes UDP socket. Should always be called after finished working with the udp-node to ensure the socket is closed and the port freed up. When the socket is closed calls passed callback.
If you want to run multiple nodes on the same machine you'll need to provide different ports to each one.
You can easily do this by passing the port
property when calling set()
on each node.
FAQs
Find and communicate with network nodes over UDP.
The npm package udp-node receives a total of 2 weekly downloads. As such, udp-node popularity was classified as not popular.
We found that udp-node demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.