Tracker example

Example 1 Shows how to create a basic public tracker, which tracks every torrent which it sees in an announce request
Example 2 Shows how to create a private tracker, which only tracks torrents explicitly registered with it

Example 1

 1         public void StartTracker ()
 2         {
 3             Tracker tracker = new Tracker();
 4 
 5             // When unregistered torrents are allowed, if a client requests peers for
 6             // a torrent which is not currently monitored by the tracker, that torrent
 7             // will be added automatically. This is useful for creating a 'public' tracker.
 8             // Normally, if this is false, announce requests for torrents not already
 9             // registered with the engine are sent an error message.
10             tracker.AllowUnregisteredTorrents = true;
11 
12             // Set the interval between announce requests to 1 hour and min interval to 10 mins
13             tracker.AnnounceInterval = TimeSpan.FromHours(1);
14             tracker.MinAnnounceInterval = TimeSpan.FromMinutes(10);
15 
16             // Create a listener which will respond to scrape/announce requests
17             // You can pass a prefix like: http://153.462.23.1/announce which will
18             // create a listener on port 80 (the default HTTP port) which will handle
19             // all announce requests.
20             HttpListener listener = new HttpListener("http://myserver.com/announce");
21             tracker.RegisterListener(listener);
22             listener.Start();
23         }

Example 2

 1         public void StartTracker ()
 2         {
 3             Tracker tracker = new Tracker();
 4 
 5             // When unregistered torrents are allowed, if a client requests peers for
 6             // a torrent which is not currently monitored by the tracker, that torrent
 7             // will be added automatically. This is useful for creating a 'public' tracker.
 8             // Normally, if this is false, announce requests for torrents not already
 9             // registered with the engine are sent an error message.
10             tracker.AllowUnregisteredTorrents = true;
11 
12             // Set the interval between announce requests to 1 hour and min interval to 10 mins
13             tracker.AnnounceInterval = TimeSpan.FromHours(1);
14             tracker.MinAnnounceInterval = TimeSpan.FromMinutes(10);
15 
16             // Create a listener which will respond to scrape/announce requests
17             // You can pass a prefix like: http://153.462.23.1/announce which will
18             // create a listener on port 80 (the default HTTP port) which will handle
19             // all announce requests.
20             HttpListener listener = new HttpListener("http://myserver.com/announce");
21             tracker.RegisterListener(listener);
22             listener.Start();
23         }