SimpleBroadcast
Simple broadcasting of JSON messages using net sockets.
Installation
Via npm on Node:
npm install simplebroadcast copy
Reference it from your program:
var simplebroadcast = require ( 'simplebroadcast' ); copy
Usage
Broadcaster (server) side
var broadcaster = simplebroadcast. createBroadcaster ();
broadcaster. listen ( 8000 ); copy
Client side
var client = simplebroadcast. createClient ();
client. on ( 'message' , function (message) {
// message processing
});
client. connect (port, host);
// broadcasting a message, after connection
client. on ( 'connect' , function () {
client. write (msg);
}
copy
A broadcaster can connect to another broadcaster. Each one is the cliente of the other.
broadcaster. connect (port, host)); copy
You can build a tree of broacasters. A tree is a graph without cycles. If the graph of broadcasters has a cycle, you messages will be send forever.
A broadcaster can act as a repeater, listening to other repeateres, or connecting as a repeater to another one.
broadcaster. listenRepeater ( 8001 );
broadcaster. connectRepeater ( 8002 , 'repeater2' ); copy
The messages sent by a repeater are sent to all clients, but not to other repeaters. The messages sent by a client are sent to the others clients and to all
repeaters. In this way, you can build a graph of repeaters, including cycles. Usually it is an star graph were each repeater is connected to all the others.
Development
git clone git://github.com/ajlopez/SimpleBroadcast.git
cd SimpleBroadcast
npm install
npm test copy
Samples
Broadcast messages to many clients sample shows
how you send and receive messages to/from many clients thru a broadcast server.
Versions
0.0.1: Published
0.0.2: Published
0.0.3: Published, updated to use SimpleMessages 0.4. Adding error event to client in code.
0.0.4: Published, updated to use SimpleMessages 0.6
Contribution
Feel free to file issues and submit
pull requests � contributions are
welcome.
If you submit a pull request, please be sure to add or update corresponding
test cases, and ensure that npm test continues to pass.
(Thanks to JSON5 by aseemk .
This file is based on that project README.md).