mpetazzoni / ttorrent

BitTorrent Java library with tracker and download client
http://mpetazzoni.github.com/ttorrent/
Apache License 2.0
1.38k stars 502 forks source link

Why does this client Program output the log ”not B-encoded?” #204

Open arabbit-fancs opened 7 years ago

arabbit-fancs commented 7 years ago

Client Program

public static void main(String[] args) {
        Client client = null;
        File filePath = new File(args[0]);
        File folder = new File(args[1]);

        try {
            client = new Client(
                    // This is the interface the client will listen on (you might need something
                    // else than localhost here).
                    InetAddress.getLocalHost(),

                    // Load the torrent from the torrent file and use the given
                    // output directory. Partials downloads are automatically recovered.
                    SharedTorrent.fromFile(
                            filePath, 
                            folder));
        } catch (IOException | NoSuchAlgorithmException e1) {
            e1.printStackTrace();
        }
        client.share();
        client.waitForCompletion();

Tracker Program

public static void main(String[] args) throws IOException, NoSuchAlgorithmException {

        // First, instantiate a Tracker object with the port you want it to listen on.
        // The default tracker port recommended by the BitTorrent protocol is 6969.
        Tracker tracker = new Tracker(new InetSocketAddress(6969));
// Then, for each torrent you wish to announce on this tracker, simply created
// a TrackedTorrent object and pass it to the tracker.announce() method:
        FilenameFilter filter = new FilenameFilter() {
            @Override
            public boolean accept(File dir, String name) {
                return name.endsWith(".torrent");
            }
        };

        for (File f : new File(args[0]).listFiles(filter)) {
            tracker.announce(TrackedTorrent.load(f));
        }
// Once done, you just have to start the tracker's main operation loop:
        tracker.start();

    }

When i run these Programs, Client Program output the log "Tracker message violates expected protocol(Could not decode tracker message(not B-encoded?)!)" Why are these Programs don't work?Is this an issue?

mpetazzoni commented 7 years ago

Are you sure the Torrent file you are serving with this tracker actually points at the tracker you are running, and not some other tracker on the internet? You can use ttorrent-torrent to display information about the torrent file and show what tracker it points to.