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 [[Tracker Example#Example-2|Example 2]] Shows how to create a private tracker, which only tracks torrents explicitly registered with it h2. Example 1
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();
}
h2. Example 2
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();
}