
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Find and communicate with network nodes over UDP.
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
})
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.
Adds a listener for a custom message. When a message of the specified type is recieved calls the passed callback.
Returns the index of the added listener, which can be used with the off method to turn it off.
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
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.