在进程后回调函数

时间:2017-04-12 18:10:46

标签: javascript node.js asynchronous bittorrent

我使用bittorent-tracker软件包获取给定torrent的播种机和leechers数量但是无法知道torrent格式化程序是否终止client.on(' scrape_terminated')例如...有没有办法检测到刮擦终止?

var Tracker = require('bittorrent-tracker')
var magnet = require('magnet-uri')
var magnetURI = "magnet:?xt=urn:btih:7a0e02e22744ddb807480f580cc328925d5810d4&dn=Terminator+2%3A+Judgment+Day+DC+%281991%29+1080p+BrRip+x264+-+YIFY&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969&tr=udp%3A%2F%2Fzer0day.ch%3A1337&tr=udp%3A%2F%2Fopen.demonii.com%3A1337&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Fexodus.desync.com%3A6969"

var parsedTorrent = magnet(magnetURI)

var opts = {
infoHash: parsedTorrent.infoHash,
announce: parsedTorrent.announce,
peerId: new Buffer('01234567890123456789'), // hex string or Buffer
port: 6881 // torrent client port
}

var client = new Tracker(opts)

client.scrape();

client.on('scrape', function (data) {
 console.log('number of seeders in the swarm: ' + data.complete)
 console.log('number of leechers in the swarm: ' + data.incomplete)
});

client.on('error',function(data) {
 console.log('erreur');
})

0 个答案:

没有答案