Skip to content

Commit

Permalink
Use the echo server for the write example
Browse files Browse the repository at this point in the history
  • Loading branch information
DamonOehlman committed Oct 24, 2014
1 parent 861e81c commit 1479b9a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,24 @@ var pull = require('pull-stream');
var ws = require('pull-ws');

// connect to the echo endpoint for test/server.js
var socket = new WebSocket('ws://localhost:3000/echo');
var socket = new WebSocket('wss://echo.websocket.org');

// write values to the socket
pull(
pull.values([ 'hi', 'there' ]),
pull.infinite(function() {
return 'hello @ ' + Date.now()
}),
// throttle so it doesn't go nuts
pull.asyncMap(function(value, cb) {
setTimeout(function() {
cb(null, value);
}, 100);
}),
ws.sink(socket)
);

socket.addEventListener('message', function(evt) {
console.log('received: ', evt.data);
console.log('received: ' + evt.data);
});

```
Expand Down
14 changes: 11 additions & 3 deletions examples/write.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,22 @@ var pull = require('pull-stream');
var ws = require('..');

// connect to the echo endpoint for test/server.js
var socket = new WebSocket('ws://localhost:3000/echo');
var socket = new WebSocket('wss://echo.websocket.org');

// write values to the socket
pull(
pull.values([ 'hi', 'there' ]),
pull.infinite(function() {
return 'hello @ ' + Date.now()
}),
// throttle so it doesn't go nuts
pull.asyncMap(function(value, cb) {
setTimeout(function() {
cb(null, value);
}, 100);
}),
ws.sink(socket)
);

socket.addEventListener('message', function(evt) {
console.log('received: ', evt.data);
console.log('received: ' + evt.data);
});

0 comments on commit 1479b9a

Please sign in to comment.