Skip to content

Instantly share code, notes, and snippets.

@seungjin
Created September 25, 2010 20:02
Show Gist options
  • Save seungjin/597235 to your computer and use it in GitHub Desktop.
Save seungjin/597235 to your computer and use it in GitHub Desktop.
<html>
<head>
<!-- http://faye.jcoglan.com/browser.html -->
<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js'>
</script>
<script type="text/javascript" src="http://localhost:8000/faye.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var client = new Faye.Client("http://localhost:8000/faye");
var subscription = client.subscribe('/email/new', function(msg){alert(msg.text);});
})
</script>
</head>
<body>
</body>
</html>
// http://faye.jcoglan.com/node.html
var http = require('http');
var faye = require('faye');
var bayeux = new faye.NodeAdapter({
mount: '/faye',
timeout: 45
});
// Handle non-Bayeux requests
var server = http.createServer(function(request,response) {
var currentTime = new Date();
console.log("non-Bayeux request received at " + currentTime + " " + request);
response.writeHead(200, {'Content-Type': 'text/plain'});
response.write('non-Bayeux request');
response.end();
});
bayeux.attach(server);
server.listen(8000);
// http://faye.jcoglan.com/node.html
var http = require('http');
var faye = require('faye');
var client = new faye.Client('http://localhost:8000/faye');
client.publish('/email/new', {text: "new mail arrived"});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment