Managing Torrents
Version 5 (olivier dufour, 04/20/2009 07:22 PM)
| 1 | 1 | h1. Client example |
|
|---|---|---|---|
| 2 | 1 | ||
| 3 | 5 | olivier dufour | h2. Simple Client |
| 4 | 5 | olivier dufour | |
| 5 | 4 | olivier dufour | <pre><code class="java"> |
| 6 | 1 | ||
| 7 | 5 | olivier dufour | ClientEngine engine = new ClientEngine(new EngineSettings(downloadsPath, port)); |
| 8 | 2 | olivier dufour | |
| 9 | 5 | olivier dufour | Torrent torrent = Torrent.Load("test.torrent"); |
| 10 | 5 | olivier dufour | TorrentManager manager = new TorrentManager(torrent, downloadsPath, torrentDefaults); |
| 11 | 5 | olivier dufour | |
| 12 | 5 | olivier dufour | engine.Register(manager); |
| 13 | 5 | olivier dufour | manager.Start (); |
| 14 | 5 | olivier dufour | |
| 15 | 5 | olivier dufour | </code> |
| 16 | 5 | olivier dufour | </pre> |
| 17 | 5 | olivier dufour | |
| 18 | 5 | olivier dufour | h2. Advanced Client |
| 19 | 5 | olivier dufour | |
| 20 | 5 | olivier dufour | |
| 21 | 5 | olivier dufour | <pre><code class="java"> |
| 22 | 5 | olivier dufour | |
| 23 | 5 | olivier dufour | |
| 24 | 1 | ClientEngine engine = new ClientEngine(new EngineSettings(downloadsPath, port)); |
|
| 25 | 1 | ||
| 26 | 1 | //DHT |
|
| 27 | 1 | DhtListener dhtListner = new UdpListener (new IPEndPoint (IPAddress.Any, port)); |
|
| 28 | 1 | DhtEngine dht = new DhtEngine (dhtListner); |
|
| 29 | 1 | engine.RegisterDht(dht); |
|
| 30 | 1 | dhtListner.Start(); |
|
| 31 | 5 | olivier dufour | //byte array of dht nodes can be null if you have never connect to DHT before today! |
| 32 | 1 | engine.DhtEngine.Start(nodes); |
|
| 33 | 1 | ||
| 34 | 1 | ||
| 35 | 1 | torrent = Torrent.Load("test.torrent"); |
|
| 36 | 1 | TorrentManager manager = new TorrentManager(torrent, downloadsPath, torrentDefaults); |
|
| 37 | 1 | ||
| 38 | 1 | //FastResume code need a BencodedDictionnary |
|
| 39 | 5 | olivier dufour | //If you jsut start the torrent, you have no fast resume |
| 40 | 5 | olivier dufour | // but if you have download a part of the torrent you can save fast resume data |
| 41 | 5 | olivier dufour | //(manager.SaveFastResume()) and restore it later to do a quicker load |
| 42 | 1 | manager.LoadFastResume(new FastResume (BEncDictFastResume)); |
|
| 43 | 1 | ||
| 44 | 1 | engine.Register(manager); |
|
| 45 | 1 | manager.Start (); |
|
| 46 | 1 | ||
| 47 | 1 | </code> |
|
| 48 | 2 | olivier dufour | </pre> |