When trying to download files at ttorrent, the log message appears like this:
1) Highlighted in blue: PEERS: just 5. The file actually has more peers.
2) Highlighted in red: these are the WARN messages I got from log4j when downloading files. The download still goes on and the file is actually downloaded, but really slow.
My code:
BasicConfigurator.configure();
// Get options
File output = new File("/home/maciej");
// Get the .torrent file path
File torrentPath = new File(
"/home/maciej/ubuntu.12.10.desktop.amd64.torrent");
// Start downloading file
try {
SharedTorrent torrent = SharedTorrent.fromFile(torrentPath, output);
System.out.println("Starting client for torrent: "
+ torrent.getName());
Client client = new Client(InetAddress.getLocalHost(), torrent);
try {
System.out.println("Start to download: " + torrent.getName());
client.share(); // SEEDING for completion signal
// client.download() // DONE for completion signal
while (!ClientState.SEEDING.equals(client.getState())) {
// Check if there's an 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 one second
TimeUnit.SECONDS.sleep(1);
}
System.out.println("download completed.");
} catch (Exception e) {
System.err.println("An error occurs...");
e.printStackTrace(System.err);
} finally {
System.out.println("stop client.");
client.stop();
}
} catch (Exception e) {
System.err.println("An error occurs...");
e.printStackTrace(System.err);
}
Although this code works fine, it has a big issue: it seems to download the file from only 1 peer, therefore the download is really slow. I'm newbie at java and probably I'm doing something wrong. But I followed the instructions exactly as shown.
PS. Thanks for this amazing library, and thanks in advance for any reply.
When trying to download files at ttorrent, the log message appears like this:
1) Highlighted in blue: PEERS: just 5. The file actually has more peers. 2) Highlighted in red: these are the WARN messages I got from log4j when downloading files. The download still goes on and the file is actually downloaded, but really slow.
My code:
Although this code works fine, it has a big issue: it seems to download the file from only 1 peer, therefore the download is really slow. I'm newbie at java and probably I'm doing something wrong. But I followed the instructions exactly as shown.
PS. Thanks for this amazing library, and thanks in advance for any reply.