Exemple #1
0
        private void button3_Click(object sender, EventArgs e)
        {
            var p = currentSelect();

            if (p != null)
            {
                master.Connect(p);
            }
        }
Exemple #2
0
        static void Main(string[] args)
        {
            SlavePeer slave = new SlavePeer();

            slave.Start(IPAddress.Any, 48361, new SlavePeerListener());

            MasterPeer master = new MasterPeer();

            master.Start(IPAddress.Any, 48360, new MasterPeerListener());
            var peer = new Peer()
            {
                EndPoint = new IPEndPoint(IPAddress.Parse("10.20.208.27"), 48361)
            };

            master.Connect(peer);

            Console.ReadKey();
            StringPacket sp = new StringPacket("hehe");

            master.Send(peer, sp.Encode());

            Console.ReadKey();
            // 传输3M的数据
            FileBlockBeginPacket begin = new FileBlockBeginPacket();

            master.Send(peer, begin.Encode());
            byte[] b3k = new byte[1024 * 3];
            for (int i = 0; i < 1024; ++i)
            {
                FileBlockDataPacket d = new FileBlockDataPacket(b3k);
                master.Send(peer, d.Encode());
            }
            FileBlockEndPacket end = new FileBlockEndPacket();

            master.Send(peer, end.Encode());

            Console.ReadKey();
        }
Exemple #3
0
        static void Main(string[] args)
        {
            task            = new DownloadTask();
            task.RemotePath = @"http://speed.myzone.cn/pc_elive_1.1.rar"; //60M
            //task.RemotePath = @"http://cd002.www.duba.net/duba/install/2011/ever/duba160406_100_50.exe"; //17M
            task.LocalPath = @"d:\hehe.rar";
            task.BlockSize = 1024 * 1024 * 3;
            if (task.InitTask())
            {
                Console.WriteLine("begin download");
            }

            Console.ReadKey();

            master = new MasterPeer();
            master.Start(IPAddress.Any, 48360, new MasterPeerListener());
            List <KeyValuePair <string, int> > peerList = new List <KeyValuePair <string, int> >()
            {
                new KeyValuePair <string, int>("127.0.0.1", 48360),
                //new KeyValuePair<string, int>("10.20.208.27", 48235),
                //new KeyValuePair<string, int>("10.20.208.27", 48362),
                //new KeyValuePair<string, int>("10.20.221.119", 48360),
                //new KeyValuePair<string, int>("10.20.208.30", 48360), //wyf
                //new KeyValuePair<string, int>("10.20.208.38", 48390), //hym
                //new KeyValuePair<string, int>("10.20.208.55", 48390), //hsj
            };

            foreach (var i in peerList)
            {
                var peer = new Peer()
                {
                    EndPoint = new IPEndPoint(IPAddress.Parse(i.Key), i.Value)
                };
                master.Connect(peer);
            }
            Console.ReadKey();
        }
Exemple #4
0
        static void Main(string[] args)
        {
            var r = Console.ReadLine();

            if (r == "master")
            {
                MasterPeer master = new MasterPeer();
                master.Start(IPAddress.Any, 48360, new MasterPeerListener());
                var peer = new Peer()
                {
                    EndPoint = new IPEndPoint(IPAddress.Parse("10.20.208.27"), 48361)
                };
                master.Connect(peer);
                Console.ReadKey();
                master.Send(peer, "kingwl");
                Console.ReadKey();
                master.Stop();
            }
            else if (r == "master2")
            {
                MasterPeer master = new MasterPeer();
                master.Start(IPAddress.Any, 48360, new MasterPeerListener());
                var peer1 = new Peer()
                {
                    EndPoint = new IPEndPoint(IPAddress.Parse("10.20.208.27"), 48361)
                };
                var peer2 = new Peer()
                {
                    EndPoint = new IPEndPoint(IPAddress.Parse("10.20.208.27"), 48362)
                };
                var peer3 = new Peer()
                {
                    EndPoint = new IPEndPoint(IPAddress.Parse("10.20.208.27"), 48363)
                };
                master.Connect(peer1);
                master.Connect(peer2);
                master.Connect(peer3);
                Console.ReadKey();
                master.Send(peer1, "kingwl");
                master.Send(peer2, "kingwlkingwl");
                master.Send(peer3, "kingwlkingwlkingwl");
                Console.ReadKey();
                master.Stop();
            }
            else if (r == "slave")
            {
                SlavePeer slave = new SlavePeer();
                slave.Start(IPAddress.Any, 48361, new SlavePeerListener());
                Console.ReadKey();
                slave.Send("hehe");
                Console.ReadKey();
                slave.Stop();
            }
            else if (r == "slave2")
            {
                SlavePeer slave = new SlavePeer();
                slave.Start(IPAddress.Any, 48362, new SlavePeerListener());
                SlavePeer slave2 = new SlavePeer();
                slave2.Start(IPAddress.Any, 48363, new SlavePeerListener());
                Console.ReadKey();
                slave.Stop();
                slave2.Stop();
            }
        }