Ttorrent无法下载文件

时间:2012-11-06 21:52:37

标签: java bittorrent

我想在我的项目中使用ttorent java lib。我试图弄清楚它是如何工作的。当我想将它用作独立程序并调用

./client -o ~ ~/file.torrent -i eth3

总是有0%。当我尝试将它用作具有如下简单代码的库时:

import java.io.File;
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 Main {

/**
 * @param args
 */
public static void main(String[] args) {
    BasicConfigurator.configure();

    // Get options
    File output = new File("/home/user");

    // Get the .torrent file path
    File torrentPath = new File("/home/user/file.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.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);
    }
}

}

它也总是0%。我尝试使用其他客户端下载这个torrent文件并且没关系,所以我认为这不乏种子。

0 个答案:

没有答案