Skip to content
This repository has been archived by the owner on Aug 29, 2023. It is now read-only.

Commit

Permalink
docs: fixing the broken example in README (#91)
Browse files Browse the repository at this point in the history
* Working example fix

* Char fix

* Corrected output, and add yarn to gitignore
  • Loading branch information
drewstone authored and daviddias committed Apr 5, 2018
1 parent df0aa05 commit 5ef2469
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ docs
test/repo-tests*
**/bundle.js

# yarn
yarn.lock

# Logs
logs
*.log
Expand Down
25 changes: 15 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,28 +39,33 @@ const TCP = require('libp2p-tcp')
const multiaddr = require('multiaddr')
const pull = require('pull-stream')

const mh1 = multiaddr('/ip4/127.0.0.1/tcp/9090')
const mh2 = multiaddr('/ip6/::/tcp/9092')
const mh = multiaddr('/ip4/127.0.0.1/tcp/9090')

const tcp = new TCP()

const listener = tcp.createListener(mh1, (socket) => {
const listener = tcp.createListener((socket) => {
console.log('new connection opened')
pull(
pull.values(['hello']),
socket
)
})

listener.listen(() => {
listener.listen(mh, () => {
console.log('listening')

pull(
tcp.dial(mh1),
pull.log,
pull.onEnd(() => {
tcp.close()
})
tcp.dial(mh),
pull.collect((err, values) => {
if (!err) {
console.log(`Value: ${values.toString()}`)
} else {
console.log(`Error: ${err}`)
}

// Close connection after reading
listener.close()
}),
)
})
```
Expand All @@ -70,7 +75,7 @@ Outputs:
```sh
listening
new connection opened
hello
Value: hello
```

## API
Expand Down

0 comments on commit 5ef2469

Please sign in to comment.