Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/316.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何使用ttorrent创建torrent文件?_Java_Distributed_Bittorrent_Data Sharing - Fatal编程技术网

Java 如何使用ttorrent创建torrent文件?

Java 如何使用ttorrent创建torrent文件?,java,distributed,bittorrent,data-sharing,Java,Distributed,Bittorrent,Data Sharing,我开始使用ttorrent()创建一个本地网络同步文件夹 我的目标是使用torrent协议同步节点硬盘中的大型文件。 但我不知道如何使用ttorrent创建新的torrent文件 我需要: 1) 新文件将添加到一个节点。 2) 其他节点接收到torent文件并开始从第一个节点下载该文件,或从已经下载该文件部分的其他节点下载该文件,从而加快下载时间。这样,我就可以避免每个节点从服务器下载千兆字节(并且整天等待) 如果不知道如何为新添加的文件创建一个torrent文件(或者是否有更好、更智能的方法)

我开始使用ttorrent()创建一个本地网络同步文件夹

我的目标是使用torrent协议同步节点硬盘中的大型文件。 但我不知道如何使用ttorrent创建新的torrent文件

我需要: 1) 新文件将添加到一个节点。 2) 其他节点接收到torent文件并开始从第一个节点下载该文件,或从已经下载该文件部分的其他节点下载该文件,从而加快下载时间。这样,我就可以避免每个节点从服务器下载千兆字节(并且整天等待)

如果不知道如何为新添加的文件创建一个torrent文件(或者是否有更好、更智能的方法),我就无法继续

我可以有一个中心点作为追踪者

谢谢。

谢谢


我建议使用单文件torrents,否则如果您想停止共享一个文件,您需要重新刷新所有文件。或者也可以使用BitComet的填充文件hack,它在公开的Torrent中并不流行,但应该适合您。
public class Main {

    public static void main(String[] args) {
        // File parent = new File("d:/echo-insurance.backup");
        String sharedFile = "d:/echo-insurance.backup";

        try {
            Tracker tracker = new Tracker( InetAddress.getLocalHost() );
            tracker.start();
            System.out.println("Tracker running.");

            System.out.println( "create new .torrent metainfo file..." );
            Torrent torrent = Torrent.create(new File(sharedFile), tracker.getAnnounceUrl().toURI(), "createdByDarren");

            System.out.println("save .torrent to file...");

            FileOutputStream fos = new FileOutputStream("d:/seed.torrent");
            torrent.save( fos );            
            fos.close();

        } catch ( Exception e ) {
            e.printStackTrace();
        }

    }

}