Hosting a tracker

Version 3 (Alan McGovern, 07/30/2009 01:35 AM)

1 1
h1. Tracker example
2 1
3 3 Alan McGovern
[[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
4 3 Alan McGovern
[[Tracker Example#Example-2|Example 2]] Shows how to create a private tracker, which only tracks torrents explicitly registered with it
5 1
6 3 Alan McGovern
h2. Example 1
7 1
8 3 Alan McGovern
<pre><code class="java">
9 3 Alan McGovern
        public void StartTracker ()
10 3 Alan McGovern
        {
11 3 Alan McGovern
            Tracker tracker = new Tracker();
12 1
13 3 Alan McGovern
            // When unregistered torrents are allowed, if a client requests peers for
14 3 Alan McGovern
            // a torrent which is not currently monitored by the tracker, that torrent
15 3 Alan McGovern
            // will be added automatically. This is useful for creating a 'public' tracker.
16 3 Alan McGovern
            // Normally, if this is false, announce requests for torrents not already
17 3 Alan McGovern
            // registered with the engine are sent an error message.
18 3 Alan McGovern
            tracker.AllowUnregisteredTorrents = true;
19 1
20 3 Alan McGovern
            // Set the interval between announce requests to 1 hour and min interval to 10 mins
21 3 Alan McGovern
            tracker.AnnounceInterval = TimeSpan.FromHours(1);
22 3 Alan McGovern
            tracker.MinAnnounceInterval = TimeSpan.FromMinutes(10);
23 3 Alan McGovern
           
24 3 Alan McGovern
            // Create a listener which will respond to scrape/announce requests
25 3 Alan McGovern
            // You can pass a prefix like: http://153.462.23.1/announce which will
26 3 Alan McGovern
            // create a listener on port 80 (the default HTTP port) which will handle
27 3 Alan McGovern
            // all announce requests.
28 3 Alan McGovern
            HttpListener listener = new HttpListener("http://myserver.com/announce");
29 3 Alan McGovern
            tracker.RegisterListener(listener);
30 3 Alan McGovern
            listener.Start();
31 3 Alan McGovern
        }
32 3 Alan McGovern
</code></pre>
33 3 Alan McGovern
34 3 Alan McGovern
h2. Example 2
35 3 Alan McGovern
36 3 Alan McGovern
<pre><code class="java">
37 3 Alan McGovern
        public void StartTracker ()
38 3 Alan McGovern
        {
39 3 Alan McGovern
            Tracker tracker = new Tracker();
40 3 Alan McGovern
41 3 Alan McGovern
            // When unregistered torrents are allowed, if a client requests peers for
42 3 Alan McGovern
            // a torrent which is not currently monitored by the tracker, that torrent
43 3 Alan McGovern
            // will be added automatically. This is useful for creating a 'public' tracker.
44 3 Alan McGovern
            // Normally, if this is false, announce requests for torrents not already
45 3 Alan McGovern
            // registered with the engine are sent an error message.
46 3 Alan McGovern
            tracker.AllowUnregisteredTorrents = true;
47 3 Alan McGovern
48 3 Alan McGovern
            // Set the interval between announce requests to 1 hour and min interval to 10 mins
49 3 Alan McGovern
            tracker.AnnounceInterval = TimeSpan.FromHours(1);
50 3 Alan McGovern
            tracker.MinAnnounceInterval = TimeSpan.FromMinutes(10);
51 3 Alan McGovern
           
52 3 Alan McGovern
            // Create a listener which will respond to scrape/announce requests
53 3 Alan McGovern
            // You can pass a prefix like: http://153.462.23.1/announce which will
54 3 Alan McGovern
            // create a listener on port 80 (the default HTTP port) which will handle
55 3 Alan McGovern
            // all announce requests.
56 3 Alan McGovern
            HttpListener listener = new HttpListener("http://myserver.com/announce");
57 3 Alan McGovern
            tracker.RegisterListener(listener);
58 3 Alan McGovern
            listener.Start();
59 3 Alan McGovern
        }
60 3 Alan McGovern
</code></pre>