Created
September 10, 2010 05:27
-
-
Save ghiden/573148 to your computer and use it in GitHub Desktop.
This file contains 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
require 'em-http' | |
EventMachine.run { | |
http = EM::HttpRequest.new("http://127.0.0.1:8000/").get | |
puts 'starting...' | |
buffer = "" | |
http.stream do |chunk| | |
buffer += chunk | |
while line = buffer.slice!(/.+\r?\n/) | |
puts line | |
end | |
puts '...' | |
end | |
} |
This file contains 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
// Text streaming using node.js and http streaming | |
// Original source is from http://blog.new-bamboo.co.uk/2009/12/7/real-time-online-activity-monitor-example-with-node-js-and-websocket | |
var sys = require('sys') | |
var filename = process.ARGV[2]; | |
if (!filename) | |
return sys.puts("Usage: node textstreaming.js filename"); | |
var spawn = require('child_process').spawn; | |
var tail = spawn("tail", ["-f", filename]); | |
sys.puts("start tailing"); | |
tail.stdout.on('data', function (data) { | |
sys.puts(data); | |
}); | |
var http = require("http"); | |
http.createServer(function(req,res){ | |
res.writeHead(200,{"Content-Type": "text/plain"}); | |
tail.stdout.on('data', function (data) { | |
res.write(data); | |
}); | |
}).listen(8000, "127.0.0.1"); | |
console.log("Server running at http://127.0.0.1") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment