简体   繁体   中英

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.

My goal is to use the torrent protocol do sync large files in nodes hard drives. But I can't see how to create a new torrent file using ttorrent.

I need to: 1) A new file is added to one node. 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. 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

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

    }

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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