36 lines
1.2 KiB
Java
36 lines
1.2 KiB
Java
package com.unisinsight.project.tb;
|
|
|
|
import com.turn.ttorrent.client.Client;
|
|
import com.turn.ttorrent.client.SharedTorrent;
|
|
|
|
import java.io.File;
|
|
import java.net.InetAddress;
|
|
|
|
public class JavaSeeder {
|
|
public static void main(String[] args) throws Exception {
|
|
// 1. 种子文件和原始文件
|
|
File torrentFile = new File("4.txt.torrent"); // 输出的种子文件
|
|
File file = new File("D:\\temp\\log\\3.txt"); // 要共享的文件
|
|
//
|
|
String trackerUrl = "udp://tracker.openbittorrent.com:80/announce"; // Tracker URL
|
|
TorrentCreator111.createTorrent(file, trackerUrl, torrentFile);
|
|
System.out.println("Torrent file created successfully: " + torrentFile.getAbsolutePath());
|
|
|
|
// 1. 加载种子和文件
|
|
SharedTorrent torrent = SharedTorrent.fromFile(
|
|
torrentFile,
|
|
file.getParentFile()
|
|
);
|
|
|
|
// 2. 创建客户端并启用 DHT
|
|
Client client = new Client(
|
|
InetAddress.getLocalHost(), // 绑定本机 IP
|
|
torrent
|
|
);
|
|
|
|
// 3. 开始做种
|
|
client.share();
|
|
System.out.println("DHT 做种已启动...");
|
|
|
|
}
|
|
} |