mirror of
https://github.com/fluencelabs/js-libp2p-tcp
synced 2025-04-25 01:52:30 +00:00
docs: fixing the broken example in README (#91)
* Working example fix * Char fix * Corrected output, and add yarn to gitignore
This commit is contained in:
parent
df0aa059ca
commit
5ef24695fc
3
.gitignore
vendored
3
.gitignore
vendored
@ -4,6 +4,9 @@ docs
|
||||
test/repo-tests*
|
||||
**/bundle.js
|
||||
|
||||
# yarn
|
||||
yarn.lock
|
||||
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
|
25
README.md
25
README.md
@ -39,12 +39,11 @@ 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']),
|
||||
@ -52,15 +51,21 @@ const listener = tcp.createListener(mh1, (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()
|
||||
}),
|
||||
)
|
||||
})
|
||||
```
|
||||
@ -70,7 +75,7 @@ Outputs:
|
||||
```sh
|
||||
listening
|
||||
new connection opened
|
||||
hello
|
||||
Value: hello
|
||||
```
|
||||
|
||||
## API
|
||||
|
Loading…
x
Reference in New Issue
Block a user