Skip to content

Instantly share code, notes, and snippets.

@seungjin
Created September 27, 2010 19:52
Show Gist options
  • Save seungjin/599694 to your computer and use it in GitHub Desktop.
Save seungjin/599694 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="/faye.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var client = new Faye.Client("/faye");
var subscription = client.subscribe('/new_log', function(msg){ $("#msg").append(msg.text+"<br/>"); });
})
</script>
</head>
<body>
<div id="msg"></div>
</body>
</html>
// http://faye.jcoglan.com/node.html
var http = require('http');
var faye = require('faye');
var fs = require('fs');
var bayeux = new faye.NodeAdapter({
mount: '/faye',
timeout: 45
});
// Handle non-Bayeux requests
var server = http.createServer(function(request,response) {
switch (request.url) {
case "/index.node" :
fs.readFile('faye.html', function(err,data) {if (err) throw err;
response.writeHead(200, {
'Content-Type': 'text/html'});
response.write( data );
response.end();
})
break;
default :
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();
break;
}
});
bayeux.attach(server);
server.listen(8000);
// http://faye.jcoglan.com/node.html
var http = require('http'), faye = require('faye');
var client = new faye.Client('http://localhost:8000/faye');
//client.publish('/new_log', {text: process.argv[2]});
var stdin = process.openStdin();
stdin.setEncoding('utf8');
//stdin.on('data', function (chunk) {client.publish('/new_log', {text: "<script type=\"text/javascript\">"+chunk+"</script>"});});
stdin.on('data', function (chunk) {client.publish('/new_log', {text: chunk});});
stdin.on('end', function () { process.stdout.write('end');});
// http://faye.jcoglan.com/node.html
var http = require('http'), faye = require('faye'), fs = require('fs');
var client = new faye.Client('http://localhost:8000/faye');
fs.watchFile('log', function(curr,prev) {
if (curr.mtime.getTime() != prev.mtime.getTime()) {
fs.readFile('log', function(err,data) {if (err) throw err;
client.publish('/new_log', {text: data.toString('utf8', 0)});
})
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment