示例#1
0
        public void DisconnectFromARemoteEndPoint()
        {
            using (var host = new LocalDriverHelper(default(NetworkEndPoint)))
            {
                host.Host();
                var driver = new NetworkDriver(new IPCNetworkInterface(), new NetworkDataStreamParameter {
                    size = 64
                });

                // Need to be connected in order to be able to send a disconnect packet.
                NetworkConnection connectionId = driver.Connect(host.EndPoint);
                Assert.True(connectionId != default(NetworkConnection));
                driver.ScheduleUpdate().Complete();

                var local = driver.LocalEndPoint();
                host.Assert_GotConnectionRequest(local, true);

                NetworkConnection con;
                DataStreamReader  slice;
                // Pump so we get the accept message back.
                driver.ScheduleUpdate().Complete();
                Assert.AreEqual(NetworkEvent.Type.Connect, driver.PopEvent(out con, out slice));
                driver.Disconnect(connectionId);
                driver.ScheduleUpdate().Complete();

                host.Assert_GotDisconnectionRequest(local);

                driver.Dispose();
            }
        }
示例#2
0
        public void Accept()
        {
            Driver.Bind(NetworkEndPoint.LoopbackIpv4);
            Driver.Listen();
            Assert.That(Driver.Listening);

            // create connection to test to connect.
            /*var remote =*/ RemoteDriver.Connect(Driver.LocalEndPoint());

            NetworkConnection id;
            DataStreamReader  reader;
            const int         maximumIterations = 10;
            int  count     = 0;
            bool connected = false;

            while (count++ < maximumIterations)
            {
                // Clear pending events
                Driver.PopEvent(out id, out reader);
                RemoteDriver.PopEvent(out id, out reader);

                Driver.ScheduleUpdate().Complete();
                RemoteDriver.ScheduleUpdate().Complete();
                var connection = Driver.Accept();
                if (connection != default(NetworkConnection))
                {
                    connected = true;
                }
            }

            Assert.That(connected);
        }
示例#3
0
        public unsafe void Assert_PopEvent(out NetworkConnection connection, NetworkEvent.Type evnt)
        {
            DataStreamReader reader;

            var retval = m_LocalDriver.PopEvent(out connection, out reader);

            Assert.True(retval == evnt);
        }
示例#4
0
        public void ConnectAttemptWithRetriesToARemoteEndPoint()
        {
            NetworkConnection connection;

            NetworkEvent.Type eventType = 0;
            DataStreamReader  reader;

            // Tiny connect timeout for this test to be quicker
            using (var client = new NetworkDriver(new IPCNetworkInterface(), new NetworkDataStreamParameter {
                size = 64
            },
                                                  new NetworkConfigParameter {
                connectTimeoutMS = 15, maxConnectAttempts = 10, fixedFrameTimeMS = 10
            }))
            {
                var hostAddress = NetworkEndPoint.LoopbackIpv4.WithPort(1);
                client.Connect(hostAddress);

                // Wait past the connect timeout so there will be unanswered connect requests
                client.ScheduleUpdate().Complete();
                client.ScheduleUpdate().Complete();

                using (var host = new LocalDriverHelper(hostAddress))
                {
                    host.Host();

                    // Now give the next connect attempt time to happen
                    // TODO: Would be better to be able to see internal state here and explicitly wait until next connect attempt happens
                    //client.ScheduleUpdate().Complete();

                    host.Assert_GotConnectionRequest(client.LocalEndPoint(), true);

                    // Wait for the client to get the connect event back
                    for (int i = 0; i < 2; ++i)
                    {
                        client.ScheduleUpdate().Complete();
                        eventType = client.PopEvent(out connection, out reader);
                        if (eventType != NetworkEvent.Type.Empty)
                        {
                            break;
                        }
                    }

                    Assert.AreEqual(NetworkEvent.Type.Connect, eventType);
                }
            }
        }