
Product
Introducing Socket Firewall Enterprise: Flexible, Configurable Protection for Modern Package Ecosystems
Socket Firewall Enterprise is now available with flexible deployment, configurable policies, and expanded language support.
unix-dgram
Advanced tools
Communicate over UNIX datagram sockets.
Server:
// One-shot server. Note that the server cannot send a reply;
// UNIX datagram sockets are unconnected and the client is not addressable.
var unix = require('unix-dgram');
var server = unix.createSocket('unix_dgram', function(buf) {
console.log('received ' + buf);
server.close();
});
server.bind('/path/to/socket');
Client:
// Send a single message to the server.
var message = Buffer('ping');
var client = unix.createSocket('unix_dgram');
client.on('error', console.error);
client.send(message, 0, message.length, '/path/to/socket');
client.close();
Caveat emptor: events and callbacks are synchronous for efficiency reasons.
Returns a new unix.Socket object. type should be 'unix_dgram'.
Throws an exception if the socket(2) system call fails.
The optional listener argument is added as a listener for the 'message'
event. The event listener receives the message as a Buffer object as its
first argument.
Create a server at path. Emits a 'listening' event on success or
an 'error' event if the bind(2) system call fails.
Associate a socket with a remote path so you can send a message without setting
the remote path. Once the socket is connected it emits a 'connect' event.
It also allows to perform some kind of congestion control as it emits a
'congestion' event when the receiving buffer is full, and a 'writable' event
when it stops being full.
Only to be used with connected sockets. It sends a message to the remote path associated with the socket
Example:
var unix = require('unix-dgram');
var client = unix.createSocket('unix_dgram');
client.on('error', function(err) {
console.error(err);
});
client.on('connect', function() {
console.log('connected');
client.on('congestion', function() {
console.log('congestion');
/* The server is not accepting data */
});
client.on('writable', function() {
console.log('writable');
/* The server can accept data */
});
var message = new Buffer('PING');
client.send(message);
});
client.connect('/tmp/server');
Send a message to the server listening at path.
buf is a Buffer object containing the message to send, offset is
the offset into the buffer and length is the length of the message.
For backwards compatibility, you can still use the socket.send function with
this same signature.
Example:
var buf = new Buffer('foobarbaz');
socket.send(buf, 3, 4, '/path/to/socket'); // Sends 'barb'.
Close the socket. If the socket was bound to a path with socket.bind(),
then you will no longer receive new messages. The file system entity
(the socket file) is not automatically unlinked.
The dgram module is a built-in Node.js module that provides an implementation of UDP datagram sockets. While it is primarily used for network communication over IP, it can also be used for local IPC with Unix domain sockets. However, it is more general-purpose and not specifically tailored for Unix domain sockets like unix-dgram.
The node-ipc package provides a comprehensive set of tools for inter-process communication in Node.js, including support for Unix sockets, TCP, and UDP. It offers more features and flexibility compared to unix-dgram, but may be overkill if you only need basic Unix datagram socket functionality.
FAQs
Unix datagram socket
The npm package unix-dgram receives a total of 1,814,258 weekly downloads. As such, unix-dgram popularity was classified as popular.
We found that unix-dgram demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers 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.

Product
Socket Firewall Enterprise is now available with flexible deployment, configurable policies, and expanded language support.

Security News
Open source dashboard CNAPulse tracks CVE Numbering Authorities’ publishing activity, highlighting trends and transparency across the CVE ecosystem.

Product
Detect malware, unsafe data flows, and license issues in GitHub Actions with Socket’s new workflow scanning support.