Exemplo n.º 1
0
    void Start()
    {
        continueRegistrationRoutine = true;
        wasHosting = false;

        if (RobotRefModel_Default == null || RobotRefModel_Default.GetComponent <Robot>() == null)
        {
            throw new Exception("Default model object must reference to a prefab with robot script!");
        }

        if (RobotRefModel_Nao == null || RobotRefModel_Nao.GetComponent <Robot>() == null)
        {
            throw new Exception("Nao model object reference to a prefab with robot script!");
        }

        if (RobotRefModel_NXT == null || RobotRefModel_NXT.GetComponent <Robot>() == null)
        {
            throw new Exception("NXT model object reference to a prefab with robot script!");
        }

        communicators = new List <Communicator>();
        listener      = new TCPDataLinkListener <ProtoBufPresentation>(this);
        _ev           = new ManualResetEvent(true);

        StartCoroutine("hostingCheck");
        StartCoroutine("handleRegistrations");
    }
        public void AcceptConnection()
        {
            _subscriber = new TestIncomingDataLinkSubscriber();

            _listener = new TCPDataLinkListener <ProtoBufPresentation>(_subscriber);

            Assert.True(_listener.Start("127.0.0.1", 1234));

            _incomingClient = new TcpClient();
            _incomingClient.Connect("127.0.0.1", 1234);

            int sleepCount = 0;

            while (!_subscriber.Connected)
            {
                if (sleepCount > 50)
                {
                    Assert.True(false, "Failed to connect within timeout.");
                    break;
                }

                Thread.Sleep(1);

                sleepCount++;
            }

            Assert.IsTrue(_subscriber.Connected);
            Assert.NotNull(_subscriber.DataLink);
            Assert.IsTrue(_subscriber.DataLink.Connected());
        }
Exemplo n.º 3
0
    void OnDestroy()
    {
        continueRegistrationRoutine = false;

        if (listener != null)
        {
            StopHosting();

            listener.Dispose();
            listener = null;
        }
    }
        public void AcceptConnection()
        {
            if (EditorPrefs.GetBool("test_tcp_asio") == false)
            {
                Debug.LogWarning("[TEST_TCPAsioConnection.AcceptConnection] Test is disabled, you can enable this test via the menu option \"Testing\"");
                Assert.That(true);
                return;
            }

            Debug.LogWarning("[TEST_TCPAsioConnection.AcceptConnection] This test will only pass when a tcp client is manually connected to the listener started in this test.");

            _subscriber = new TestIncomingDataLinkSubscriberCopy();

            _listener = new TCPDataLinkListener <ProtoBufPresentation>(_subscriber);
            //use public IP address not localhost/127.0.0.1
            //use eduroam(same network)
            try
            {
                Assert.True(_listener.Start("145.93.45.16", 1234));
            }
            catch (SocketException ex)
            {
                Assert.That(false, "Invalid ip address\n" + ex.Message);
            }


            int sleepCount = 0;

            while (!_subscriber.Connected)
            {
                if (sleepCount > 500)
                {
                    Assert.True(false, "Failed to connect within timeout.");
                    break;
                }

                Thread.Sleep(20);

                sleepCount++;
            }
            Debug.Log("Actually connected");
            //Thread.Sleep(8000);

            Assert.IsTrue(_subscriber.Connected);
            Assert.NotNull(_subscriber.DataLink);
            Assert.IsTrue(_subscriber.DataLink.Connected());

            if (_subscriber.Connected)
            {
                Thread.Sleep(3000);
                Communicator          comm = new Communicator(_subscriber.DataLink, new ProtoBufPresentation());
                Communication.Message m    = new Message
                {
                    messageType   = Communication.MessageType_.ShapeUpdate,
                    messageTarget = Communication.MessageTarget_.Robot,
                    id            = 5
                };

                Shape_ sh = new Shape_();
                sh.id = 15;
                Vector3_ v = new Vector3_
                {
                    x = 3.0f,
                    y = 3.0f,
                    z = 4.0f
                };

                Vector3_ v1 = new Vector3_
                {
                    x = -1.0f,
                    y = -3.0f,
                    z = -5.5f
                };
                sh.vertices.Add(v);
                sh.vertices.Add(v1);

                Shape_ sh2 = new Shape_();
                sh2.id = 2;
                Vector3_ v2 = new Vector3_
                {
                    x = 3.4f,
                    y = 3.1f,
                    z = 4.7f
                };
                sh2.vertices.Add(v2);

                m.shapeUpdateInfo = new ShapeUpdateInfo_();
                //m.shapeUpdateInfo.changedShapes = new List<Shape_>();
                m.shapeUpdateInfo.changedShapes.Add(sh);
                m.shapeUpdateInfo.changedShapes.Add(sh2);
                m.customMessage      = new CustomMessage_();
                m.customMessage.key  = "asdf";
                m.customMessage.data = "asdf data";

                Assert.IsTrue(comm.SendCommand(m));
            }
        }