Hosting a tracker

Version 2 (olivier dufour, 04/08/2009 10:27 PM) → Version 3/6 (Alan McGovern, 07/30/2009 01:35 AM)


h1. Tracker example

[[Tracker Example#Example-1|Example 1]] Shows how to create a basic public tracker, which tracks every torrent which it sees in an announce request <pre>
[[Tracker Example#Example-2|Example 2]] Shows how to create a private tracker, which only tracks torrents explicitly registered with it <code class="java">

h2. Example 1

<pre><code class="java">
public void StartTracker ()
{
Tracker
tracker = new Tracker();

// When unregistered torrents are allowed, if a client requests peers for
// a torrent which is not currently monitored by the tracker, that torrent
// will be added automatically. This is useful for creating a 'public' tracker.
// Normally, if this is false, announce requests for torrents not already
// registered with the engine are sent an error message.

tracker.AllowUnregisteredTorrents = true;

// Set the interval between announce requests to 1 hour and min interval to 10 mins
tracker.AnnounceInterval = TimeSpan.FromHours(1);
tracker.MinAnnounceInterval = TimeSpan.FromMinutes(10);

// Create a listener which will respond to scrape/announce requests
// You can pass a prefix like: http://153.462.23.1/announce which will
// create a listener on port 80 (the default HTTP port) which will handle
// all announce requests.
HttpListener listener = new HttpListener("http://myserver.com/announce");

tracker.RegisterListener(listener);

listener.Start();
}


//trackable inehrit from ITrackable and must implement getters:

</code></pre> // TorrentFile[] Files, InfoHash InfoHash, string Name

h2. Example 2 tracker.Add(trackable);

<pre><code class="java">
public void StartTracker ()
{
Tracker tracker = new Tracker();

// When unregistered torrents are allowed, if a client requests peers for
// a torrent which is not currently monitored by the tracker, that torrent
// will be added automatically. This is useful for creating a 'public' tracker.
// Normally, if this is false, announce requests for torrents not already
// registered with the engine are sent an error message.
tracker.AllowUnregisteredTorrents = true;

// Set the interval between announce requests to 1 hour and min interval to 10 mins
tracker.AnnounceInterval = TimeSpan.FromHours(1);
tracker.MinAnnounceInterval = TimeSpan.FromMinutes(10);

// Create a listener which will respond to scrape/announce requests
// You can pass a prefix like: http://153.462.23.1/announce which will
// create a listener on port 80 (the default HTTP port) which will handle
// all announce requests.
HttpListener listener = new HttpListener("http://myserver.com/announce");
tracker.RegisterListener(listener);
listener.Start();
}
</code>
</code></pre> </pre>