コード例 #1
0
        public IEnumerator Server_ShouldSendRpc()
        {
            NewClientServer();
            serverWorld.Listen();
            yield return(new WaitForSeconds(0.1f));

            clientWorld.Connected += e => serverWorld.World.CreateRpcRequest <PlayModeTestRequest>();
            clientWorld.Connect();

            int maxCount = 60;

            while (maxCount >= 0 && !clientConnected && !clientConnectFailed)
            {
                yield return(new WaitForSeconds(0.1f));

                maxCount--;
            }

            /*Assert.IsNotNull(clientWorld, "cw");
             * Assert.IsNotNull(clientWorld.World, "cww");
             * Assert.IsNotNull(clientWorld.World.GetExistingSystem<CreateRpcRequestSystem>(), "cws");*/

            PlayModeTestRequestReceiveSystem system =
                clientWorld.World.GetExistingSystem <PlayModeTestRequestReceiveSystem>();

            maxCount = 60;
            while (maxCount >= 0 && !system.ReceivedRpc)
            {
                yield return(new WaitForSeconds(0.1f));

                maxCount--;
            }

            Assert.IsTrue(system.ReceivedRpc);
        }
コード例 #2
0
        public IEnumerator Server_ShouldSendRpcToMultipleClients()
        {
            ClientWorld client2 = new ClientWorld(new ClientOptions
            {
                Address   = "127.0.0.1",
                Port      = (ushort)(21650 + testCount),
                WorldName = $"TestServer_ShouldSendRpcToMultipleClients{testCount}"
            });

            Debug.Log((ushort)(21650 + testCount));
            NewClientServer();


            serverWorld.Listen();
            yield return(new WaitForSeconds(0.3f));

            clientWorld.Connect();
            yield return(new WaitForSeconds(0.2f));

            bool client2Connected = false;
            bool client2Failed    = false;

            client2.Connected        += e => client2Connected = true;
            client2.ConnectionFailed += s => client2Failed = true;
            client2.Connect();
            yield return(new WaitForSeconds(0.2f));

            int maxCount = 90;

            while (maxCount >= 0 && !(clientConnected || clientConnectFailed) && !(client2Connected || client2Failed))
            {
                yield return(new WaitForSeconds(0.1f));

                maxCount--;
            }

            Assert.IsTrue(clientConnected, "Client 1 did not connect to begin test");
            Assert.IsTrue(client2Connected, "Client 2 did not connect to begin test");

            serverWorld.World.CreateRpcRequest <PlayModeTestRequest>(
                serverWorld.GetNetworkConnectionEntityById(clientWorld.NetworkId));
            serverWorld.World.CreateRpcRequest <PlayModeTestRequest>(
                serverWorld.GetNetworkConnectionEntityById(client2.NetworkId));

            /*Assert.IsNotNull(clientWorld, "cw");
             * Assert.IsNotNull(clientWorld.World, "cww");
             * Assert.IsNotNull(clientWorld.World.GetExistingSystem<CreateRpcRequestSystem>(), "cws");*/

            PlayModeTestRequestReceiveSystem system1 =
                clientWorld.World.GetExistingSystem <PlayModeTestRequestReceiveSystem>();
            PlayModeTestRequestReceiveSystem system2 =
                client2.World.GetExistingSystem <PlayModeTestRequestReceiveSystem>();

            maxCount = 60;
            while (maxCount >= 0 && !system1.ReceivedRpc && !system2.ReceivedRpc)
            {
                yield return(new WaitForSeconds(0.1f));

                maxCount--;
            }

            Assert.IsTrue(system1.ReceivedRpc && system2.ReceivedRpc);
        }