Forum Moderators: phranque
IE: Say I have an XML file that I need thousands of different websites to be able to "download" and then process on the client-side but cannot host the XML file myself.
The solution i've been thinking of would involve a JS implementation of hte bitttorrent protocol but a few searches turned up nothing.
Wondered if anyone here might make some suggestions?
Thanks
Think of the implications, otherwise.
The whole point of Javascript is that it runs in a safe sandbox and is not able to access local computer files or anything on the Internet outside of the site it was downloaded from.
And, so, it's simply not possible to write a BitTorrent client in Javascript. It would break Javascript's simple security model.
Java has a more complex security model, and this is certainly possible in Java, but would require the user to give permission. And this is why users trust Javascript and have reservations about Java.
The only other choice you have is to require your users to install the BitTorrent client of their choice.
The whole point of Javascript is that it runs in a safe sandbox and is not able to access local computer files or anything on the Internet outside of the site it was downloaded from.
What about when JS calls an RSS file for example, and parses it into links? Isnt that the same as accessing things from the internet outside of the site it is downloaded from?
First, let me establish that I am talking about client-side, browser-hosted Javascript. I'll just use the term "Javascript" as a shorthand, so I don't have to keep repeating that... There are server-side implementations of Javascript, and there are stand-alone versions that don't run in a browser, and that is not what I am talking about here. I am talking about the Javascript embedded in popular browsers, such as MSIE, Firefox, etc.
Javascript has absolutely no networking capability whatsover. You CAN'T implement Bittorrent in Javascript, because there are no functions for opening or reading from a socket. The only "networking" in Javascript is the ability to tell the browser to fetch the content of a URL. That content can be fetched into a browser window, or can be fetched into the cache without being displayed (so that the Javascript program can insert it into the DOM - this is done for button animation, etc.). That content can be in any format (HTML, JPG, etc.). But it is fetched, by the browser, using any of the protocols supported BY THE BROWSER. There's no facility for implementing some protocol other than those supported by the browser. Bittorrent has it's own protocol, which isn't directly supported by popular browsers.
Now, if the user has a Bittorrent plugin installed in the browser, then, sure, you could access files using that. But the user would first have to install the Bittorrent client and plugin.
Further, there is no file I/O capability in Javascript. This may or may not be a problem for your application.
Javascript does have "signed scripts", which allow the security policy to be broken. This is similar to java's signed scripts. The user is given a warning, and asked if they want to permit the signed script to run. Signed scripts are a proprietary feature of specific Javascript implementations, though, and, as far as I know, they won't give you a socket library with which to implement Bittorrent. (They do give you the ability to read and write local files, which is a good reason for users to never allow a signed script to run...)