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

Commit 1ffd549

Browse files
committed
chore: update README
1 parent 776a524 commit 1ffd549

File tree

1 file changed

+19
-23
lines changed

1 file changed

+19
-23
lines changed

README.md

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
[![](https://raw.githubusercontent.com/libp2p/interface-connection/master/img/badge.png)](https://github.com/libp2p/interface-connection)
1414

1515

16-
> JavaScript implementation of the TCP module for libp2p. It exposes the [interface-transport](https://github.com/libp2p/interface-connection) for dial/listen. `libp2p-tcp` is a very thin shim that adds support for dialing to a `multiaddr`. This small shim will enable libp2p to use other different transports.
16+
> JavaScript implementation of the TCP module for libp2p. It exposes the [interface-transport](https://github.com/libp2p/interface-connection) for dial/listen. `libp2p-tcp` is a very thin shim that adds support for dialing to a `multiaddr`. This small shim will enable libp2p to use other transports.
1717
1818
## Lead Maintainer
1919

@@ -41,37 +41,33 @@
4141
```js
4242
const TCP = require('libp2p-tcp')
4343
const multiaddr = require('multiaddr')
44-
const pull = require('pull-stream')
44+
const pipe = require('it-pipe')
45+
const { collect } = require('streaming-iterables')
4546

4647
const mh = multiaddr('/ip4/127.0.0.1/tcp/9090')
4748

4849
const tcp = new TCP()
4950

5051
const listener = tcp.createListener((socket) => {
5152
console.log('new connection opened')
52-
pull(
53-
pull.values(['hello']),
53+
pipe(
54+
['hello'],
5455
socket
5556
)
5657
})
5758

58-
listener.listen(mh, () => {
59-
console.log('listening')
60-
61-
pull(
62-
tcp.dial(mh),
63-
pull.collect((err, values) => {
64-
if (!err) {
65-
console.log(`Value: ${values.toString()}`)
66-
} else {
67-
console.log(`Error: ${err}`)
68-
}
69-
70-
// Close connection after reading
71-
listener.close()
72-
}),
73-
)
74-
})
59+
await listener.listen(mh)
60+
console.log('listening')
61+
62+
const socket = await tcp.dial(mh)
63+
const values = await pipe(
64+
socket,
65+
collect
66+
)
67+
console.log(`Value: ${values.toString()}`)
68+
69+
// Close connection after reading
70+
await listener.close()
7571
```
7672

7773
Outputs:
@@ -88,12 +84,12 @@ Value: hello
8884

8985
[![](https://raw.githubusercontent.com/libp2p/interface-transport/master/img/badge.png)](https://github.com/libp2p/interface-transport)
9086

91-
`libp2p-tcp` accepts TCP addresses both IPFS and non IPFS encapsulated addresses, i.e:
87+
`libp2p-tcp` accepts TCP addresses as both IPFS and non IPFS encapsulated addresses, i.e:
9288

9389
`/ip4/127.0.0.1/tcp/4001`
9490
`/ip4/127.0.0.1/tcp/4001/ipfs/QmHash`
9591

96-
Both for dialing and listening.
92+
(both for dialing and listening)
9793

9894
### Connection
9995

0 commit comments

Comments
 (0)