News for hackers. Stuff that matters.
Re:Turn any application that uses stdin/stdout into a WebSoc... by kaoD on Tuesday December 10, 2013 @09:38AM (#6880922)
Nice! I love Node for these kind of asynchronous handling of data, it fits perfectly. Keep in mind you can go down the stream route. Instead of:

    ps.stdout.on 'data', (data) -> ws.send data.toString()
    ws.on 'message', (data) -> ps.stdin.write data.toString()
Just do:

    ps.stdout.pipe ws
    ws.pipe ps.stdin
I started using Node before Streams and I often forget piping too!

I still have a question for Node.js experts... would the 'close' events had to be handled then? Streams handle and propagate the 'end' event just fine, but should the underlying resource be closed? I guess killing `ps` is mandatory since ending `stdout` won't kill the process (or will it?), but is closing `ws` still mandatory too?

Re:Turn any application that uses stdin/stdout into a WebSoc... by wpears on Tuesday December 10, 2013 @01:19PM (#6882490)
If the socket is terminated mid-command (thus emitting 'close'), one would want the process to be killed. Also, the socket doesn't know that no more transmission is required just because one particular stream is over. That is why close is called manually on the socket after the stream emits a 'close'.

This all provided you use a streaming web socket module like https://github.com/maxogden/websocket-stream

Re:Turn any application that uses stdin/stdout into a WebSoc... by tlrobinson on Tuesday December 10, 2013 @01:11PM (#6882422)
I thought about using pipe but the WebSocket library doesn't implement the Stream API, does it?
Re:Turn any application that uses stdin/stdout into a WebSoc... by secoif on Tuesday December 10, 2013 @07:41PM (#6885074)