Implementation of an Echo protocol
An implementation of a simple Echo protocol.
Any data received by the receiver will be sent back to the sender.
import { noise } from '@chainsafe/libp2p-noise'
import { yamux } from '@chainsafe/libp2p-yamux'
import { echo } from '@libp2p/echo'
import { peerIdFromString } from '@libp2p/peer-id'
import { createLibp2p } from 'libp2p'
const receiver = await createLibp2p({
addresses: {
listen: ['/ip4/0.0.0.0/tcp/0']
},
connectionEncrypters: [noise()],
streamMuxers: [yamux()],
services: {
echo: echo()
}
})
const sender = await createLibp2p({
addresses: {
listen: ['/ip4/0.0.0.0/tcp/0']
},
connectionEncrypters: [noise()],
streamMuxers: [yamux()],
services: {
echo: echo()
}
})
const stream = await sender.dialProtocol(receiver.getMultiaddrs(), sender.services.echo.protocol)
// write/read stream
$ npm i @libp2p/echo
<script>
tagLoading this module through a script tag will make its exports available as Libp2pEcho
in the global namespace.
<script src="https://unpkg.com/@libp2p/echo/dist/index.min.js"></script>
Licensed under either of
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.
An implementation of a simple Echo protocol.
Any data received by the receiver will be sent back to the sender.
Example