Build highly distributed services by allowing your node applications to share emitted events over tcp socket connections.
Applications can act as a server (allowing for incoming connections) or a client (connecting to a server). Public Radio allows you to create a graph of nodes made up of server and clients that can emit events that will be received by all the other nodes, as well as allowing them to bind callbacks to specific events they are interested in.
Creating a server that will listen for incoming connections
var Server = Server;var server = 5000;server;
Creating a client to connect to a server
var Client = Client;var client = 'localhost' 5000;client;client;
Connect servers to other servers to share your events with them and their clients
Setting up a listener for an event on a server
Emitting an event from a server
Setting up a listener for an event on a client
Emitting an event from the client
The final argument of the emitted event can be a function
(replies have to be received within 60 seconds)
The listener can reply to the emitting node via a function passed as the final argument
So in this case the function passed to emit will be called with 'SELL SELL SELL!'
Setting up this network
var Server = ServerClient = Client;var server1 = 5000server2 = 5001;server1;var client1 = 'localhost' 5000client2 = 'localhost' 5000client3 = 'localhost' 5001;client1;client1;client2;client2;client3;client3;
Big thanks to @zufferguffin for the delightfully awesome header image.