Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
eladb committed Dec 21, 2011
1 parent b7f8938 commit c18fdee
Showing 1 changed file with 58 additions and 1 deletion.
59 changes: 58 additions & 1 deletion README.md
Expand Up @@ -33,7 +33,64 @@ $ wsclient http://localhost:5000
undefined
> x
{ damn: 'i am in the node.js repl' }
>
```
Here's how to bind a webstream to a spawned process:
```javascript
// server.js
var spawn = require('child_process').spawn;
var http = require('http');
var webstream = require('webstream');
var server = http.createServer();
server.listen(5000);
webstream.bind(server, function(stream) {
console.log('Client connected.');
var proc = spawn('/bin/bash', [ '-i', '-l' ]);
// stdout & stderr
proc.stdout.on('data', function(data) { stream.write(data); });
proc.stderr.on('data', function(data) { stream.write(data); });
proc.on('exit', function(status) {
stream.write('Process exited with status ' + status + '\n');
stream.end();
});
stream.on('data', function(data) {
proc.stdin.write(data);
});
stream.on('close', function() {
console.log('Client disconnected.');
});
});
```
Connect via ```wsclient```:
```bash
$ bin/wsclient http://localhost:5000
bash: no job control in this shell
$ ls -l
ls -l
total 32
-rw-r--r-- 1 eladb staff 1058 Dec 21 19:07 LICENSE
-rw-r--r-- 1 eladb staff 1764 Dec 21 19:31 README.md
drwxr-xr-x 3 eladb staff 102 Dec 21 18:33 bin
drwxr-xr-x 4 eladb staff 136 Dec 21 17:25 lib
-rw-r--r-- 1 eladb staff 45 Dec 21 18:00 main.js
drwxr-xr-x 6 eladb staff 204 Dec 21 19:12 node_modules
-rw-r--r-- 1 eladb staff 507 Dec 21 19:28 package.json
drwxr-xr-x 4 eladb staff 136 Dec 21 17:24 samples
drwxr-xr-x 3 eladb staff 102 Dec 21 19:08 test
$ exit
exit
logout
Process exited with status 0
```
## API
Expand Down

0 comments on commit c18fdee

Please sign in to comment.