示例#1
0
        static void Main(string[] args)
        {
            Torrent torrent       = new Torrent(BenDecoder.Decode(args[0]));
            Tracker trackerClient = new Tracker(torrent);

            Console.WriteLine("Connecting to tracker at {0}", torrent.AnnounceUri);
            object cv = new object();

            trackerClient.Connected += delegate
            {
                Console.WriteLine("Connected to {0}", torrent.AnnounceUri);
            };
            trackerClient.Updated += delegate
            {
                if (trackerClient.LastResponse.IsSuccessful)
                {
                    Console.WriteLine("{0} Seeders, {1} leechers", trackerClient.LastResponse.NumberOfSeeds, trackerClient.LastResponse.NumberOfLeechers);
                    ConnectToPeers(trackerClient.LastResponse.Peers, torrent);
                }
                else
                {
                    QuitWithError(cv, trackerClient.LastResponse.FailureReason);
                }
            };
            trackerClient.Error += delegate(object sender, Exception e)
            {
                QuitWithError(cv, e.Message);
            };
            trackerClient.Start();
            lock (cv)
            {
                Monitor.Wait(cv);
            }
        }
示例#2
0
        private void OpenTorrent()
        {
            OpenFileDialog openTorrent = new OpenFileDialog();

            if (openTorrent.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
            {
                torrent = new Torrent(BenDecoder.Decode(openTorrent.FileName));
            }
        }
示例#3
0
        static void Main(string[] args)
        {
            string     filename = args[0];
            BenDecoder decoder  = new BenDecoder(File.OpenRead(filename));
            Torrent    torrent  = new Torrent(decoder.ReadDictionary());

            Console.WriteLine("Tracker: {0}", torrent.AnnounceUri);
            Console.WriteLine("Number of pieces: {0}", torrent.Pieces.Count);
            Console.WriteLine("Piece length: {0}", torrent.PieceLength);
            Console.WriteLine("Hash: {0}", torrent.InfoHash.ToHexString());
            Console.WriteLine("Files:");
            foreach (ITorrentFile file in torrent.Files)
            {
                Console.WriteLine("  Name: {0}, Size: {1}", file.Name, file.Length);
            }
        }