Security News
Bun 1.2 Released with 90% Node.js Compatibility and Built-in S3 Object Support
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
@alien-worlds/aw-broadcast
Advanced tools
Broadcast is a robust, scalable and efficient module for establishing inter-process communication. The package presents a suite of interfaces, types, and implementations leveraging TCP sockets to allow seamless data exchange between distributed services.
Broadcast is a robust, scalable and efficient module for establishing inter-process communication. The package presents a suite of interfaces, types, and implementations leveraging TCP sockets to allow seamless data exchange between distributed services.
TCP (Transmission Control Protocol) is a communication protocol that ensures reliable, ordered, and error-checked delivery of data packets between applications running on networked hosts. In this package, TCP sockets serve as the communication endpoints for transmitting data between the processes.
This package is especially useful for building distributed systems, where different processes or services need to communicate with each other in a seamless and efficient way.
To add Broadcast to your project, use the following command with your favorite package manager:
yarn add @alien-worlds/aw-broadcast
Server listens to incoming network connections from clients and provides them with data or services. You can set up the server as follows:
const server: BroadcastServer = new BroadcastTcpServer({ host: 'localhost', port: 9000 });
// Optionally set a handler for all incoming messages from clients
server.onMessage((message: BroadcastMessage) => {
// handle broadcast message
});
await server.start();
If needed, the server can also send messages to clients or a specific channel:
server.sendMessage(BroadcastMessage.sendChannelMessage(...));
The Broadcast TCP Server implementation includes these features:
To start the client, follow these steps:
const client: BroadcastClient = new BroadcastTcpClient({ host: 'localhost', port: 9000 }, <optional_client_name>);
client.onMessage('channel_name', (message: BroadcastMessage) => {
// Handle incoming message
});
client.connect();
To send a message to a channel or a specific client, call the sendMessage
method with the BroadcastMessage
object:
client.sendMessage(BroadcastMessage.sendChannelMessage(...));
BroadcastMessage
is a utility to create messages within the broadcast system. It provides several static methods for message creation. Each message contains an ID, client, channel, name, data, and a persistence flag.
id
: The unique identifier of the message.client
: The target client for the message.channel
: The target channel for the message.name
: Optional name of the message.data
: The data to be sent in the message.persistent
: Determines whether the message is persistent and whether to add it to the stack in the event of a message undelivered. Default value is true
Creates a message to be sent to a specific channel.
const message = BroadcastMessage.createChannelMessage('room_1', 'Hello world');
Creates a message to be sent to a specific client.
const message = BroadcastMessage.createClientMessage('user1', 'Hello world');
Creates a message to be sent to several channels at once.
const message = BroadcastMessage.createMultiChannelMessage(['room_1', 'room_2'], 'Hello world');
Creates a message to be sent to a group of clients.
const message = BroadcastMessage.createGroupMessage(['user1', 'user2'], 'Hello world');
Creates a message that can be sent to both a specific client and a specific channel.
const message = BroadcastMessage.create('user1', 'room_1', 'Hello world');
By leveraging the BroadcastMessage
utility, you can easily manage the creation and sending of messages within your distributed systems.
This package has been meticulously designed and built to provide a solid foundation for your distributed systems. By understanding the key concepts outlined above, you should be able to start using
it effectively. Enjoy seamless inter-process communication with Broadcast!
We welcome contributions from the community. Before contributing, please read through the existing issues on this repository to prevent duplicate submissions. New feature requests and bug reports can be submitted as an issue. If you would like to contribute code, please open a pull request.
This project is licensed under the terms of the MIT license. For more information, refer to the LICENSE file.
FAQs
Broadcast is a robust, scalable and efficient module for establishing inter-process communication. The package presents a suite of interfaces, types, and implementations leveraging TCP sockets to allow seamless data exchange between distributed services.
The npm package @alien-worlds/aw-broadcast receives a total of 5 weekly downloads. As such, @alien-worlds/aw-broadcast popularity was classified as not popular.
We found that @alien-worlds/aw-broadcast demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 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.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Security News
Biden's executive order pushes for AI-driven cybersecurity, software supply chain transparency, and stronger protections for federal and open source systems.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.