You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Aug 29, 2023. It is now read-only.
> Node.js implementation of the TCP module that libp2p uses, which implements
15
-
> the [interface-connection](https://github.com/libp2p/interface-connection)
16
-
> interface for dial/listen.
13
+
> Node.js implementation of the TCP module that libp2p uses, which implements the [interface-connection](https://github.com/libp2p/interface-connection) interface for dial/listen.
17
14
18
15
## Description
19
16
20
-
`libp2p-tcp` in Node.js is a very thin shim that adds support for dialing to a
21
-
`multiaddr`. This small shim will enable libp2p to use other different
22
-
transports.
17
+
`libp2p-tcp` in Node.js is a very thin shim that adds support for dialing to a`multiaddr`. This small shim will enable libp2p to use other different transports.
18
+
19
+
**Note:** This module uses [pull-streams](https://pull-stream.github.io) for all stream based interfaces.
23
20
24
21
## Example
25
22
26
23
```js
27
24
constTCP=require('libp2p-tcp')
28
25
constmultiaddr=require('multiaddr')
26
+
constpull=require('pull-stream')
29
27
30
28
constmh1=multiaddr('/ip4/127.0.0.1/tcp/9090')
31
29
constmh2=multiaddr('/ip6/::/tcp/9092')
32
30
33
31
consttcp=newTCP()
34
32
35
-
var listener =tcp.createListener(mh1, functionhandler (socket) {
We expose a streaming interface based on `pull-streams`, rather then on the Node.js core streams implementation (aka Node.js streams). `pull-streams` offers us a better mechanism for error handling and flow control guarantees. If you would like to know more about what took us to make this migration, see the discussion at this [issue](https://github.com/ipfs/js-ipfs/issues/362).
73
+
74
+
You can learn more about pull-streams at:
75
+
76
+
-[The history of Node.js streams, nodebp April 2014](https://www.youtube.com/watch?v=g5ewQEuXjsQ)
77
+
-[The history of streams, 2016](http://dominictarr.com/post/145135293917/history-of-streams)
78
+
-[pull-streams, the simple streaming primitive](http://dominictarr.com/post/149248845122/pull-streams-pull-streams-are-a-very-simple)
If you are a Node.js streams user, you can convert a pull-stream to Node.js Stream using the module `pull-stream-to-stream`, giving you an instance of a Node.js stream that is linked to the pull-stream. Example:
0 commit comments