private void TestPipeline(int packetCount, NetworkPipeline serverPipe, int packetDelay = 100)
        {
            // Connect to server
            var clientToServer  = m_ClientDriver.Connect(m_ServerDriver.LocalEndPoint());
            var clientToServer2 = m_ClientDriver2.Connect(m_ServerDriver.LocalEndPoint());

            Assert.AreNotEqual(default(NetworkConnection), clientToServer);
            Assert.AreNotEqual(default(NetworkConnection), clientToServer2);
            m_ClientDriver.ScheduleUpdate().Complete();
            m_ClientDriver2.ScheduleUpdate().Complete();

            // Driver only updates time in update, so must read start time before update
            var startTime = Stopwatch.GetTimestamp() / TimeSpan.TicksPerMillisecond;

            // Handle incoming connection from client
            m_ServerDriver.ScheduleUpdate().Complete();
            var serverToClient = m_ServerDriver.Accept();

            Assert.AreNotEqual(default(NetworkConnection), serverToClient);
            var serverToClient2 = m_ServerDriver.Accept();

            Assert.AreNotEqual(default(NetworkConnection), serverToClient2);

            // Send given packetCount number of packets in a row in one update
            // Write 1's for packet 1, 2's for packet 2 and so on and verify they're received in same order
            var strm = new DataStreamWriter(64, Allocator.Temp);

            for (int i = 0; i < packetCount; i++)
            {
                strm.Clear();
                for (int j = 0; j < 16; j++)
                {
                    strm.Write((int)i + 1);
                }
                m_ServerDriver.Send(serverPipe, serverToClient, strm);
                m_ServerDriver.Send(serverPipe, serverToClient2, strm);
            }

            m_ServerDriver.ScheduleUpdate().Complete();

            // Receive incoming message from server
            m_ClientDriver.ScheduleUpdate().Complete();
            m_ClientDriver2.ScheduleUpdate().Complete();
            DataStreamReader readStrm;

            Assert.AreEqual(NetworkEvent.Type.Connect, clientToServer.PopEvent(m_ClientDriver, out readStrm));
            Assert.AreEqual(NetworkEvent.Type.Connect, clientToServer.PopEvent(m_ClientDriver2, out readStrm));

            ClientReceivePackets(m_ClientDriver, packetCount, clientToServer, startTime, packetDelay);
            ClientReceivePackets(m_ClientDriver2, packetCount, clientToServer2, startTime, packetDelay);
        }
 public void NetworkPipeline_CreatePipelineAfterConnectFails()
 {
     m_ClientDriver.Connect(m_ServerDriver.LocalEndPoint());
     Assert.Throws <InvalidOperationException>(() => { m_ClientDriver.CreatePipeline(typeof(TestPipelineStageWithHeader)); });
 }
Example #3
0
 public NetworkConnection Connect(NetworkEndPoint endpoint)
 {
     return(m_genericDriver.Connect(endpoint));
 }