Skip to content

Instantly share code, notes, and snippets.

@Nuhvi
Last active March 4, 2023 19:51
Show Gist options
  • Save Nuhvi/501ff7b94c4c62a997b8315d3606fc92 to your computer and use it in GitHub Desktop.
Save Nuhvi/501ff7b94c4c62a997b8315d3606fc92 to your computer and use it in GitHub Desktop.
hyperswarm works
// Run https://gist.github.com/Nazeh/64edc0fa2d0920f55eb8b4df227c93c9
// on one machine, then run this code on another passing the publicKey
// logged from the server `node hyperswarm-works-connect.js <publicKey>`
// then you should be able to connect to your peer and start chatting!
// If not, run https://github.com/holepunchto/hyperswarm-doctor
// to check both of your networks, if both have randomized ports, holepunching won't work.
import DHT from '@hyperswarm/dht'
const publicKeyHex = process.argv[2]
const node = new DHT()
// publicKey here is keyPair.publicKey from above
const socket = node.connect(Buffer.from(publicKeyHex, 'hex'))
socket.on('open', function () {
// socket fully open with the other peer
console.log("Connected to", publicKeyHex)
})
// pipe it somewhere like any duplex stream
process.stdin.pipe(socket).pipe(process.stdout)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment