简体   繁体   English

如何使用ttorrent创建torrent文件?

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

I'm starting to use ttorrent ( Turn's BitTorrent Java library ) to create a local network synchronized folder. 我开始使用ttorrent( Turn的BitTorrent Java库 )创建本地网络同步文件夹。

My goal is to use the torrent protocol do sync large files in nodes hard drives. 我的目标是使用torrent协议同步节点硬盘中的大文件。 But I can't see how to create a new torrent file using ttorrent. 但是我看不到如何使用ttorrent创建新的torrent文件。

I need to: 1) A new file is added to one node. 我需要:1)将一个新文件添加到一个节点。 2) Other nodes receive the torent file and start do download this file from the first node or pieces from other nodes that already downloaded that file part, speeding the downloading time. 2)其他节点接收torent文件,并开始从第一个节点下载该文件,或者从已经下载该文件的其他节点下载该文件,从而缩短了下载时间。 This way I can avoid each node to download gigabytes from a server (and wait all day). 这样,我可以避免每个节点从服务器下载千兆字节(并等待一整天)。

I can't go ahead without knowing how to create a torrent file for that new added file (or if a better and smart way exists). 我不能不知道如何为该新添加的文件创建种子文件(或者是否存在更好且更聪明的方式)。

I can have a central point to serve as tracker. 我可以有一个中心点来充当跟踪器。

Thanks. 谢谢。

Thanks to fujohnwang 感谢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