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.
import{tcp}from'@libp2p/tcp'import{multiaddr}from'@multiformats/multiaddr'import{pipe}from'it-pipe'importallfrom'it-all'// A simple upgrader that just returns the MultiaddrConnectionconstupgrader={upgradeInbound: asyncmaConn=>maConn,upgradeOutbound: asyncmaConn=>maConn}consttransport=tcp()()constlistener=transport.createListener({
upgrader,handler: (socket)=>{console.log('new connection opened')pipe(['hello',' ','World!'],socket)}})constaddr=multiaddr('/ip4/127.0.0.1/tcp/9090')awaitlistener.listen(addr)console.log('listening')constsocket=awaittransport.dial(addr,{ upgrader })constvalues=awaitpipe(socket,all)console.log(`Value: ${values.toString()}`)// Close connection after readingawaitlistener.close()
Outputs:
listening
new connection opened
Value: hello World!
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