I am trying to broadcast a message through the Node.js
service socket.io
(http://socket.io/) to certain subset of all subscribers.
To be more exact, I would like to use channels that users can subscribe to, in order to efficiently push messages to a couple hundred people at the same time.
I'm not really sure ifaddEvent('channel_name',x)
is the way to go.
I have not found anything in the docs. Any ideas?
Thanks Mat
This is a little late(!) but I spotted it in my referrer logs (I'm the author of Faye). It's easy to publish messages from your application whether it's in the same server as Faye or not. For example:
var faye = require('faye'),
http = require('http');
// Set up the server
var server = http.createServer(function(req, res) {
// dispatch to your app logic...
});
var bayeux = new faye.NodeAdapter({mount: '/bayeux'});
bayeux.attach(server);
server.listen(8000);
If your app logic is in the same server process you can do this:
bayeux.getClient().publish('/channel', {hello: 'world'});
Otherwise you can make a client in Node that connects to your Faye server:
var client = new faye.Client('http://0.0.0.0:8000/bayeux');
client.publish('/channel', {hello: 'world'});
Either way, the Faye server will relay the message to any subscribed clients whether they are server- or client-side. Hope that helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With