Gordon Hall
11 years ago
1 changed files with 19 additions and 24 deletions
@ -1,32 +1,27 @@ |
|||||
var Peer = require('../Peer'); |
var Peer = require('../Peer'); |
||||
var Connection = require('../Connection'); |
var Connection = require('../Connection'); |
||||
|
var dns = require('dns'); |
||||
|
|
||||
// create a peer instance from a know peer
|
// get a peer from dns seed
|
||||
// (later we can use built-in peer discovery)
|
dns.resolve('dnsseed.bluematt.me', function(err, seeds) { |
||||
// to get a peer to connect to you can run:
|
// use the first peer
|
||||
//
|
var peer = new Peer(seeds[0], 8333); |
||||
// ~# dig dnsseed.bluematt.me
|
|
||||
//
|
|
||||
// (or use a different dns seed)
|
|
||||
var peer = new Peer('108.13.10.109', 8333); |
|
||||
|
|
||||
// create a connection without an existing socket
|
// create a connection without an existing socket
|
||||
// but specify a socks5 proxy to create a socket
|
// but specify a socks5 proxy to create a socket
|
||||
// that's bound to that proxy in it's place
|
// that's bound to that proxy in it's place
|
||||
var connection = new Connection(null, peer, { |
var connection = new Connection(null, peer, { |
||||
proxy: { host: '127.0.0.1', port: 9050 } |
proxy: { host: '127.0.0.1', port: 9050 } |
||||
}); |
}); |
||||
|
|
||||
// open the connection
|
connection.open(); |
||||
connection.open(); |
|
||||
|
|
||||
// you can listen for the connect event
|
connection.on('connect', function(data) { |
||||
connection.on('connect', function(data) { |
console.log('connected through socks5!'); |
||||
// we are connected!
|
}); |
||||
console.log('connected'); |
|
||||
}); |
connection.on('error', function(err) { |
||||
|
console.log(err); |
||||
|
}); |
||||
|
|
||||
connection.on('error', function(err) { |
|
||||
// boo! :(
|
|
||||
console.log(err); |
|
||||
}); |
}); |
||||
|
Loading…
Reference in new issue