Created
July 24, 2014 16:27
-
-
Save ben-bradley/7a3c0ffeccad974a7952 to your computer and use it in GitHub Desktop.
simple example of faye & express
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var faye = require('faye'), | |
express = require('express'); | |
var app = express(), | |
pubsub = new faye.NodeAdapter({ | |
mount: '/pubsub', | |
timeout: 45 | |
}); | |
app.get('/', function (req, res) { | |
res.send('ok'); | |
}); | |
var server = app.listen(3001); | |
pubsub.attach(server); | |
// server configured, now build a client | |
var client = pubsub.getClient(); | |
client.subscribe('/blargh', function (msg) { | |
console.log('CLIENT RX:', msg); | |
}); | |
setInterval(function () { | |
var msg = { | |
ts: new Date().getTime() | |
}; | |
console.log('CLIENT TX:', msg); | |
client.publish('/blargh', msg); | |
}, 1500); | |
// Now build a client using the non-built-in method | |
var otherclient = new faye.Client('http://localhost:3001/pubsub'); | |
setInterval(function () { | |
var msg = { | |
blargh: 'honk' | |
}; | |
console.log('OCLIENT TX:', msg); | |
otherclient.publish('/blargh', msg); | |
}, 3000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment