Ejemplo n.º 1
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();
        }
Ejemplo n.º 2
0
Archivo: Program.cs Proyecto: sgww/cozy
        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();
        }