Managing Torrents

Version 4 (olivier dufour, 04/08/2009 08:59 AM) → Version 5/18 (olivier dufour, 04/20/2009 07:22 PM)


h1. Client example

h2. Simple Client

<pre><code class="java">

ClientEngine engine = new ClientEngine(new EngineSettings(downloadsPath, port));

Torrent torrent = Torrent.Load("test.torrent");
TorrentManager manager = new TorrentManager(torrent, downloadsPath, torrentDefaults);

engine.Register(manager);
manager.Start ();

</code>
</pre>

h2. Advanced Client


<pre><code class="java">

ClientEngine engine = new ClientEngine(new EngineSettings(downloadsPath, port));

//DHT
DhtListener dhtListner = new UdpListener (new IPEndPoint (IPAddress.Any, port));
DhtEngine dht = new DhtEngine (dhtListner);
engine.RegisterDht(dht);
dhtListner.Start();
//byte array of dht nodes can be null if you have never connect to DHT before today!

engine.DhtEngine.Start(nodes);

torrent = Torrent.Load("test.torrent");
TorrentManager manager = new TorrentManager(torrent, downloadsPath, torrentDefaults);

//FastResume code need a BencodedDictionnary
//If you jsut start the torrent, you have no fast resume
// but if you have download a part of the torrent you can save fast resume data
//(manager.SaveFastResume()) and restore it later to do a quicker load

manager.LoadFastResume(new FastResume (BEncDictFastResume));

engine.Register(manager);
manager.Start ();

</code>
</pre>