bittorrent - issue at downloading torrents java -
i'm trying build java torrent downloader, based on ttorrent java library (link goes docs , basic instructions).
i followed instructions listed in javadoc , are. when running code, notthing appears happen. no exceptions either. , file not downloaded, can't see ".part" file in downloads folder. stays @ 0%.
this code far (compare code in docs).
client client = new client( inetaddress.getlocalhost(), sharedtorrent.fromfile( new file(torrentpath), new file(mkpath))); client.download(); client.waitforcompletion();
i didn't find better documentation of ttorrent one. doing wrong? , of course, torrent has seeds because downloaded before torrent manager.
update: although nothing downloaded, download process appears start throws following log message:
i know examples there aren't great, here 1 starter point you:
torrenttest.java
import jargs.gnu.cmdlineparser; import java.io.file; import java.io.printstream; import java.net.inetaddress; import java.util.concurrent.timeunit; import org.apache.log4j.basicconfigurator; import com.turn.ttorrent.client.client; import com.turn.ttorrent.client.client.clientstate; import com.turn.ttorrent.client.sharedtorrent; public class torrenttest { public static final string default_tracker_uri = "http://localhost:6969/announce"; /** * display program usage on given {@link printstream}. * */ private static void usage(printstream s) { s.println("usage: simpleclient [options] torrent"); s.println("leech , seed torrent file."); s.println(); s.println("available options:"); s.println(" -h,--help show , exit."); s.println(" -o,--output dir output directory file."); s.println(); } /** * main program function. * * @param args */ public static void main(string[] args) { basicconfigurator.configure(); cmdlineparser parser = new cmdlineparser(); cmdlineparser.option = parser.addbooleanoption('h', "help"); cmdlineparser.option outputstring = parser.addstringoption('o', "output"); try { parser.parse(args); } catch (cmdlineparser.optionexception oe) { system.err.println(oe.getmessage()); usage(system.err); system.exit(1); } // display , exit if requested if (boolean.true.equals((boolean)parser.getoptionvalue(help))) { usage(system.out); system.exit(0); } // options file output = new file((string) parser.getoptionvalue(outputstring, ".")); // check it's correct usage string[] otherargs = parser.getremainingargs(); if (otherargs.length != 1) { usage(system.err); system.exit(1); } // .torrent file path file torrentpath = new file(otherargs[0]); // start downloading file try { sharedtorrent torrent = sharedtorrent.fromfile(torrentpath, output); system.out.println("starting client torrent: "+torrent.getname()); client client = new client(inetaddress.getlocalhost(), torrent); try { system.out.println("start download: "+torrent.getname()); client.share(); // seeding completion signal // client.download() // done completion signal while (!clientstate.seeding.equals(client.getstate())) { // check if there's error if (clientstate.error.equals(client.getstate())) { throw new exception("ttorrent client error state"); } // display statistics system.out.printf("%f %% - %d bytes downloaded - %d bytes uploaded\n", torrent.getcompletion(), torrent.getdownloaded(), torrent.getuploaded()); // wait 1 second timeunit.seconds.sleep(1); } system.out.println("download completed."); } catch (exception e) { system.err.println("an error occurs..."); e.printstacktrace(system.err); } { system.out.println("stop client."); client.stop(); } } catch (exception e) { system.err.println("an error occurs..."); e.printstacktrace(system.err); } } }
Comments
Post a Comment