I've got the problem that, Transmission client able to download files from the torrent only when one of clients(ttorrent clients) downloading file(not in seed mode).
Please help, I need to seed to the Transmission clients.
Here is my Tracker code:
import com.turn.ttorrent.tracker.TrackedTorrent;
import com.turn.ttorrent.tracker.Tracker;
import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.security.NoSuchAlgorithmException;
import java.util.concurrent.TimeUnit;
public class TtorrentServer {
public static void main(String[] args)
throws IOException, NoSuchAlgorithmException, InterruptedException {
Tracker tracker = new Tracker(new InetSocketAddress(6969));
FilenameFilter filter = new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return name.endsWith(".torrent");
}
};
for (File f : new File(".").listFiles(filter)) {
TrackedTorrent trackedTorrent = TrackedTorrent.load(f);
tracker.announce(trackedTorrent);
}
tracker.start();
Thread.sleep(TimeUnit.DAYS.toMillis(100));
tracker.stop();
}
}
Here is the code of master client:
import com.turn.ttorrent.client.Client;
import com.turn.ttorrent.client.SharedTorrent;
import com.turn.ttorrent.common.Torrent;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.concurrent.TimeUnit;
import static java.nio.file.StandardOpenOption.CREATE;
public class TtorrentClientMaster {
public static void main(String[] args)
throws IOException, NoSuchAlgorithmException, URISyntaxException, InterruptedException {
ArrayList<File> files = new ArrayList<>();
listf("files", files);
Torrent torrent = SharedTorrent.create(
new File("files"),
files,
new URI("http://0.0.0.0:6969/announce"),
"Hronom"
);
try (OutputStream outputStream = Files.newOutputStream(Paths.get("files.torrent"), CREATE)) {
torrent.save(outputStream);
}
Client client = new Client(null, new SharedTorrent(torrent, new File(".")));
client.share();
Thread.sleep(TimeUnit.DAYS.toMillis(100));
client.stop();
}
public static void listf(String directoryName, ArrayList<File> files) throws IOException {
File directory = new File(directoryName);
// get all the files from a directory
File[] fList = directory.listFiles();
for (File file : fList) {
if (file.isFile()) {
files.add(file);
} else if (file.isDirectory()) {
listf(file.getPath(), files);
}
}
}
}
I've got the problem that, Transmission client able to download files from the torrent only when one of clients(ttorrent clients) downloading file(not in seed mode). Please help, I need to seed to the Transmission clients.
Here is my Tracker code:
Here is the code of master client:
Here is the code of my slave client: