Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/libp2p/js-libp2p-tcp
JavaScript implementation of the TCP module that libp2p uses that implements the interface-transport spec
https://github.com/libp2p/js-libp2p-tcp
Last synced: 9 days ago
JSON representation
JavaScript implementation of the TCP module that libp2p uses that implements the interface-transport spec
- Host: GitHub
- URL: https://github.com/libp2p/js-libp2p-tcp
- Owner: libp2p
- License: other
- Archived: true
- Created: 2015-09-15T13:42:08.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2023-07-21T15:48:33.000Z (over 1 year ago)
- Last Synced: 2024-08-12T21:27:47.723Z (3 months ago)
- Language: TypeScript
- Homepage: https://libp2p.io
- Size: 1.78 MB
- Stars: 76
- Watchers: 22
- Forks: 40
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
- awesome-peer-to-peer - libp2p-tcp
README
# 📁 Archived - this module has been merged into [js-libp2p](https://github.com/libp2p/js-libp2p/tree/master/packages/transport-tcp)
# @libp2p/tcp
[![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/)
[![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io)
[![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p-tcp.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p-tcp)
[![CI](https://img.shields.io/github/actions/workflow/status/libp2p/js-libp2p-tcp/js-test-and-release.yml?branch=master\&style=flat-square)](https://github.com/libp2p/js-libp2p-tcp/actions/workflows/js-test-and-release.yml?query=branch%3Amaster)> A TCP transport for libp2p
## Table of contents
- [Install](#install)
- [Usage](#usage)
- [API Docs](#api-docs)
- [License](#license)
- [Contribution](#contribution)## Install
```console
$ npm i @libp2p/tcp
```## Usage
```js
import { tcp } from '@libp2p/tcp'
import { multiaddr } from '@multiformats/multiaddr'
import { pipe } from 'it-pipe'
import all from 'it-all'// A simple upgrader that just returns the MultiaddrConnection
const upgrader = {
upgradeInbound: async maConn => maConn,
upgradeOutbound: async maConn => maConn
}const transport = tcp()()
const listener = transport.createListener({
upgrader,
handler: (socket) => {
console.log('new connection opened')
pipe(
['hello', ' ', 'World!'],
socket
)
}
})const addr = multiaddr('/ip4/127.0.0.1/tcp/9090')
await listener.listen(addr)
console.log('listening')const socket = await transport.dial(addr, { upgrader })
const values = await pipe(
socket,
all
)
console.log(`Value: ${values.toString()}`)// Close connection after reading
await listener.close()
```Outputs:
```sh
listening
new connection opened
Value: hello World!
```## API Docs
-
## License
Licensed under either of
- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / )
- MIT ([LICENSE-MIT](LICENSE-MIT) / )## Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.