Skip to content

Instantly share code, notes, and snippets.

@AcidLeroy
Created June 21, 2018 14:27
Show Gist options
  • Save AcidLeroy/ad3efc4280409fb77462cd48665274e6 to your computer and use it in GitHub Desktop.
Save AcidLeroy/ad3efc4280409fb77462cd48665274e6 to your computer and use it in GitHub Desktop.
http discovery client
const DC = require('discovery-channel')
const crypto = require('crypto')
const http = require('http');
let id = process.argv[2]
if (!id) {
console.log('You must have an ID')
process.exit(1)
}
let channel = DC({dht: true}) // set true to work over the internet
channel.join(id)
channel.once('peer', function (peerId, peer, type) {
console.log('New peer %s:%s found via %s', peer.host, peer.port, type)
http.get('http://'+peer.host+':'+peer.port, (resp) => {
let data = '';
// A chunk of data has been recieved.
resp.on('data', (chunk) => {
data += chunk;
});
// The whole response has been received. Print out the result.
resp.on('end', () => {
console.log('You received =' + data);
});
}).on("error", (err) => {
console.log("Error: " + err.message);
});
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment