2

プロジェクトで 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 ファイルをダウンロードしようとしましたが、問題はなかったので、これはシードの不足ではないと思います。

4

0 に答える 0