Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Seed and download file on the local machine sometimes successfully #946

Closed
tailiu opened this issue Oct 12, 2016 · 2 comments
Closed

Seed and download file on the local machine sometimes successfully #946

tailiu opened this issue Oct 12, 2016 · 2 comments
Labels

Comments

@tailiu
Copy link

@tailiu tailiu commented Oct 12, 2016

Hi, I am using the Webtorrent API to seed and download files locally. When there are many files being seeded locally and each file is being seeded by one seed(that's why only 0 in torrentSeeds[0] below), some downloaders could block at 'torrent.on('done', callback). In other words, after those downloader calls addPeer(), torrent will not be done forever and there is not any error message. I am really confused why some wait forever, while some can download successfully. Here is the code:

Seeder:

var torrent = new WebTorrent({ dht: false, tracker: false })
  torrent.seed(filePath , function (value) {
    callback(filemeta)
  })

Downloader:

  var client = new WebTorrent({ dht: false, tracker: false })
  var torrent = client.add(torrentSeeds[0].infoHash)

  torrent.addPeer(torrentSeeds[0].ipAddr + ':' + torrentSeeds[0].torrentPort)

  torrent.on('done', function() {
      torrent.files.forEach(function(file){
        var ws = fs.createWriteStream(downloadedFilePath)
        var rs = file.createReadStream()
        rs.pipe(ws)
        rs.on('end', function(){
          callback()
        })
     })
  })

  • WebTorrent version:
  • Node.js version: v6.5.0

Thanks.

@feross feross added the question label Oct 13, 2016
@feross

This comment has been minimized.

Copy link
Member

@feross feross commented Oct 13, 2016

It looks like you are creating a separate webtorrent client instance for each torrent. That will probably overwhelm your network with DHT traffic. Try using a single webtorrent client across your whole webtorrent process.

@feross feross closed this Oct 13, 2016
@lock

This comment has been minimized.

Copy link

@lock lock bot commented May 4, 2018

This thread has been automatically locked because it has not had recent activity. To discuss futher, please open a new issue.

@lock lock bot locked as resolved and limited conversation to collaborators May 4, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.