示例#1
0
        public void TestClientPacketRequester()
        {
            TCPConnection tcp1;
            TCPConnection tcp2;

            establishTCP(out tcp1, out tcp2);


            tcp1.Receiving = true;
            tcp2.Receiving = true;

            IClientPacketRequester <DataPacket, ErrorPacket> requester;

            ClientPacketManagerNetworked manager1 = new ClientPacketManagerNetworked(tcp1);

            manager1.DisableUDP();

            requester = manager1.CreatePacketRequester("Test1",
                                                       new DataPacketFactory(),
                                                       new ErrorPacketFactory(),
                                                       delegate(DataPacket packet)
            {
                return(new ErrorPacket("Received: " + packet.Number.ToString() + " - " + packet.Text));
            },
                                                       PacketFlags.TCP);



            manager1.AutoAssignPacketIDs();


            ClientPacketManagerNetworked manager2 = new ClientPacketManagerNetworked(tcp2);

            manager2.DisableUDP();

            requester = manager2.CreatePacketRequester("Test1", new DataPacketFactory(), new ErrorPacketFactory(),
                                                       PacketFlags.TCP);

            manager2.SyncronizeRemotePacketIDs();

            ErrorPacket ep;

            ep = requester.SendRequest(new DataPacket("Hello", 345));
            Assert.AreEqual(ep.Description, "Received: 345 - Hello");

            ep = requester.SendRequest(new DataPacket("Goodbye", 8));
            Assert.AreEqual(ep.Description, "Received: 8 - Goodbye");


            /*dataTransporter.Send( new Test.DataPacket( "Hello", 345 ) );
             *
             * Assert.AreEqual( dp.Text, "Hello" );
             * Assert.AreEqual( dp.Number, 345 );*/
        }