public void TestTransmitUserInputNetworked()
        {
            TCPConnection conn1, conn2;

            NetworkingUtilities.EstablishTwoWayTCP(out conn1, out conn2);
            conn1.Receiving = true;
            conn2.Receiving = true;

            var man1 = new ClientPacketManagerNetworked(conn1);
            var man2 = new ClientPacketManagerNetworked(conn2);

            man1.DisableUDP();
            man2.DisableUDP();
            var gen = createPacketGen();

            var proxyTrans = man1.CreatePacketTransporter("Test", gen.GetFactory <UserInputHandlerPacket>(), PacketFlags.TCP);
            var realTrans  = man2.CreatePacketTransporter("Test", gen.GetFactory <UserInputHandlerPacket>(), PacketFlags.TCP);

            gen.BuildFactoriesAssembly();


            man2.AutoAssignPacketIDs();
            man1.SyncronizeRemotePacketIDs();

            testInputHandler(proxyTrans, realTrans);
        }
Esempio n. 2
0
        public void TestClientPacketManagerSyncronizeSynchronous()
        {
            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.CreatePacketTransporter("Test1", new DataPacketFactory(), PacketFlags.TCP);
            manager1.CreatePacketTransporter("Test2", new ErrorPacketFactory(), PacketFlags.TCP);
            manager1.DisableUDP();

            manager1.AutoAssignPacketIDs();


            ClientPacketManagerNetworked manager2 = new ClientPacketManagerNetworked(tcp2);

            manager2.CreatePacketTransporter("Test1", new ErrorPacketFactory(), PacketFlags.TCP);
            manager2.CreatePacketTransporter("Test2", new DataPacketFactory(), PacketFlags.TCP);
            manager2.DisableUDP();
            manager2.SyncronizeRemotePacketIDs();
        }
Esempio n. 3
0
        public void TestClientTransporterSinglePacket()
        {
            TCPConnection tcp1;
            TCPConnection tcp2;

            establishTCP(out tcp1, out tcp2);


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

            AutoResetEvent serverReadyEvent = new AutoResetEvent(false);

            Thread t1 = new Thread(
                delegate()
            {
                ClientPacketManagerNetworked manager = new ClientPacketManagerNetworked(tcp1);
                manager.DisableUDP();
                IClientPacketTransporter <DataPacket> dataTransporter;

                dataTransporter = manager.CreatePacketTransporter("Test1", new DataPacketFactory(), PacketFlags.TCP);

                manager.AutoAssignPacketIDs();

                serverReadyEvent.Set();


                DataPacket dp = dataTransporter.Receive();

                Assert.AreEqual(dp.Text, "Hello");
                Assert.AreEqual(dp.Number, 345);
            });



            Thread t2 = new Thread(
                delegate()
            {
                serverReadyEvent.WaitOne();

                ClientPacketManagerNetworked manager = new ClientPacketManagerNetworked(tcp2);
                manager.DisableUDP();
                IClientPacketTransporter <DataPacket> dataTransporter;

                dataTransporter = manager.CreatePacketTransporter("Test1", new DataPacketFactory(), PacketFlags.TCP);

                manager.SyncronizeRemotePacketIDs();

                dataTransporter.Send(new DataPacket("Hello", 345));
            });


            t1.Start();
            t2.Start();
            t1.Join();
            t2.Join();

            Assert.True(t1.ThreadState != ThreadState.Running && t2.ThreadState != ThreadState.Running);
        }
Esempio n. 4
0
        public void TestClientPacketManagerSyncronizeAsynchronous()
        {
            TCPConnection tcp1;
            TCPConnection tcp2;

            establishTCP(out tcp1, out tcp2);

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

            AutoResetEvent serverReadyEvent       = new AutoResetEvent(false);
            ClientPacketManagerNetworked manager1 = null;
            ClientPacketManagerNetworked manager2 = null;

            Thread t1 = new Thread(
                delegate()
            {
                manager1 = new ClientPacketManagerNetworked(tcp1);
                manager1.DisableUDP();
                IClientPacketTransporter <DataPacket> dataTransporter;

                manager1.CreatePacketTransporter("DataPacket", new DataPacketFactory(), PacketFlags.TCP);
                manager1.CreatePacketTransporter("MyOwnTestTransporter", new ErrorPacketFactory(), PacketFlags.TCP);

                manager1.AutoAssignPacketIDs();

                serverReadyEvent.Set();
            });



            Thread t2 = new Thread(
                delegate()
            {
                serverReadyEvent.WaitOne();

                manager2 = new ClientPacketManagerNetworked(tcp2);
                manager2.DisableUDP();

                manager2.CreatePacketTransporter("DataPacket", new ErrorPacketFactory(), PacketFlags.TCP);
                manager2.CreatePacketTransporter("MyOwnTestTransporter", new DataPacketFactory(), PacketFlags.TCP);

                manager2.SyncronizeRemotePacketIDs();
            });


            t1.Start();
            t2.Start();
            t1.Join(3000);
            t2.Join(3000);

            /*t1.Join();
            *  t2.Join();*/

            Assert.True(t1.ThreadState != ThreadState.Running && t2.ThreadState != ThreadState.Running);
        }
Esempio n. 5
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 );*/
        }