A lightweight node port of websocketd, originally written in go.
node-websocketd --port=8080 ./count.sh
A lightweight node port of websocketd, originally written in go.
node-websocketd --port=8080 ./count.sh
var spawn = require('child_process').spawn; | |
var Server = require('ws').Server; | |
var Stream = require('websocket-stream'); | |
var argv = require('optimist').argv; | |
var server = new Server({ port: argv.port }); | |
server.on('connection', function(ws) { | |
var stream = Stream(ws); | |
var ps = spawn(argv._[0], argv._.slice(1)); | |
ps.stdout.pipe(stream).pipe(ps.stdin); | |
stream.on('end', ps.kill.bind(ps)); | |
}); |