Пример #1
0
        public void ClientToServerTest()
        {
            Assert.That(connectionToClient.address, Is.EqualTo("localhost"));

            bool invoked = false;

            void Handler(NetworkConnection conn, TestMessage message)
            {
                invoked = true;
            }

            // set up handler on the server connection
            NetworkServer.RegisterHandler <TestMessage>(Handler, false);

            connectionToServer.Send(new TestMessage());
            connectionToServer.Update();

            Assert.True(invoked, "handler should have been invoked");
        }
Пример #2
0
        public void ServerToClient()
        {
            Assert.That(connectionToClient.address, Is.EqualTo("localhost"));

            bool invoked = false;

            void Handler(NetworkConnection conn, NetworkReader reader, int channelId)
            {
                invoked = true;
            }

            Dictionary <ushort, NetworkMessageDelegate> handlers = new Dictionary <ushort, NetworkMessageDelegate>();

            handlers.Add(MessagePacking.GetId <TestMessage>(), Handler);

            connectionToClient.SetHandlers(handlers);
            connectionToServer.Send(new TestMessage());

            connectionToServer.Update();

            Assert.True(invoked, "handler should have been invoked");
        }