Skip to content
This repository has been archived by the owner on Aug 29, 2023. It is now read-only.
/ js-libp2p-tcp Public archive

JavaScript implementation of the TCP module that libp2p uses that implements the interface-transport spec

License

Unknown and 2 other licenses found

Licenses found

Unknown
LICENSE
Unknown
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

libp2p/js-libp2p-tcp

Repository files navigation

📁 Archived - this module has been merged into js-libp2p

@libp2p/tcp

libp2p.io Discuss codecov CI

A TCP transport for libp2p

Table of contents

Install

$ npm i @libp2p/tcp

Usage

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:

listening
new connection opened
Value: hello World!

API Docs

License

Licensed under either of

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.

About

JavaScript implementation of the TCP module that libp2p uses that implements the interface-transport spec

Resources

License

Unknown and 2 other licenses found

Licenses found

Unknown
LICENSE
Unknown
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Packages

No packages published