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

How to use the file tranfer part only #365

Closed
aliraza0337 opened this issue Jun 28, 2015 · 10 comments
Closed

How to use the file tranfer part only #365

aliraza0337 opened this issue Jun 28, 2015 · 10 comments

Comments

@aliraza0337
Copy link

@aliraza0337 aliraza0337 commented Jun 28, 2015

Hi I want to use the file transfer part only from the webtorrent, can you please guide me how to do that ?

@feross

This comment has been minimized.

Copy link
Member

@feross feross commented Jun 28, 2015

I don't understand what you mean by "only the file transfer part". Can you elaborate?

What are you trying to do?

@aliraza0337

This comment has been minimized.

Copy link
Author

@aliraza0337 aliraza0337 commented Jun 29, 2015

Hi Thanks for your response,
I have a seprate mechanism[I have already implimented this] through which I know who is hosting the files I want, Lets say H[some machine or and ip address to which I can connect] is hosting a file F. How I can download F using this torrent protocol.

@feross

This comment has been minimized.

Copy link
Member

@feross feross commented Jun 29, 2015

It's not enough that you know who has the file. They have to be seeding the file using a torrent client. If you can do that, then you're good.

You'll want to disable the normal peer finding via trackers and the DHT.

var client = new WebTorrent({ dht: false, tracker: false })
client.seed('/path/to/file', function (torrent) {
  console.log(torrent.infoHash) // get info hash
  console.log(client.torrentPort) // get torrent port
})

Then from the downloader's end:

var client = new WebTorrent({ dht: false, tracker: false })
var torrent = client.add(infoHash)
torrent.addPeer('ip:port') // use ip and port of remote machine

Hope this helps!

@feross feross closed this Jun 29, 2015
@aliraza0337

This comment has been minimized.

Copy link
Author

@aliraza0337 aliraza0337 commented Jun 29, 2015

Yes I can run the client for seeding the file as well, Thanks Alot, I will test and update here if it works.

@aliraza0337

This comment has been minimized.

Copy link
Author

@aliraza0337 aliraza0337 commented Jun 29, 2015

if multiple machies are hosting the same file is there any way I can pass the ip addresses of all so that it can download faster [the usuall chunk based downloading]?
plus where the downloder will save the file after downloading?

@feross

This comment has been minimized.

Copy link
Member

@feross feross commented Jun 29, 2015

Just call torrent.addPeer('ip:port') multiple times if you have multiple peers to download from.

You can specify download location with the path option to client.add. Read the documentation to learn how it works.

@aliraza0337

This comment has been minimized.

Copy link
Author

@aliraza0337 aliraza0337 commented Jun 29, 2015

I tried to run both instances on one machine,
I got infohas from sender and put that as string in receiver.
I got the port number from one and put 'localhost:portnumber' in the downloader here is the error

/Users/aliraza/node_modules/webtorrent/lib/torrent.js:385
self.swarm.addPeer(peer)
^
TypeError: Cannot read property 'addPeer' of undefined
at Torrent.addPeer (/Users/aliraza/node_modules/webtorrent/lib/torrent.js:385:15)
at Object. (/Users/aliraza/Desktop/receiver.js:5:9)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.Module.runMain (module.js:501:10)
at startup (node.js:129:16)
at node.js:814:3

@feross

This comment has been minimized.

Copy link
Member

@feross feross commented Jun 29, 2015

localhost is not a valid IP address.
On Sun, Jun 28, 2015 at 6:32 PM aliraza0337 notifications@github.com
wrote:

I tried to run both instances on one machine,
I got the port number from one and put 'localhost:portnumber' in the
downloader here is the error

/Users/aliraza/node_modules/webtorrent/lib/torrent.js:385
self.swarm.addPeer(peer)
^
TypeError: Cannot read property 'addPeer' of undefined
at Torrent.addPeer
(/Users/aliraza/node_modules/webtorrent/lib/torrent.js:385:15)
at Object. (/Users/aliraza/Desktop/receiver.js:5:9)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.Module.runMain (module.js:501:10)
at startup (node.js:129:16)
at node.js:814:3


Reply to this email directly or view it on GitHub
#365 (comment).

@aliraza0337

This comment has been minimized.

Copy link
Author

@aliraza0337 aliraza0337 commented Jun 29, 2015

I tried 127.0.0.1 as well it didn't work.
Is there any way I can print the IP address of sender as well like we get the port?

@feross

This comment has been minimized.

Copy link
Member

@feross feross commented Jun 29, 2015

Ah, the downloader needs to wait until the 'infoHash' or 'listening' event before self.swarm is defined, and before you can call torrent.addPeer(peer).

I just published a new version of WebTorrent (0.50.2) that fixes this. So update to that and try this:

Seeder

var WebTorrent = require('webtorrent')
var client = new WebTorrent({ dht: false, tracker: false })
client.seed('README.md', function (torrent) {
  console.log(torrent.infoHash) // get info hash
  console.log(client.torrentPort) // get torrent port
})

Downloader

var WebTorrent = require('webtorrent')
var client = new WebTorrent({ dht: false, tracker: false })
var torrent = client.add('037596f40092d714b57a919f5628c6d3930debd0') // replace with your infohash
torrent.addPeer('127.0.0.1:52472') // replace with your port
torrent.on('done', function () {
  console.log('all done!')
})
feross added a commit that referenced this issue Jun 29, 2015
@lock lock bot locked as resolved and limited conversation to collaborators May 6, 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.