繁体   English   中英

如何使用ttorrent创建torrent文件?

[英]How to use ttorrent to create a torrent file?

我开始使用ttorrent( Turn的BitTorrent Java库 )创建本地网络同步文件夹。

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

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

我不能不知道如何为该新添加的文件创建种子文件(或者是否存在更好且更聪明的方式)。

我可以有一个中心点来充当跟踪器。

谢谢。

感谢fujohnwang

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();
        }

    }

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM