Esempio n. 1
0
        public void TestProtocolPartialRecv()
        {
            int recvCount = 0;

            wise.Network.Instance.Subscribe(new PacketSample(), (m) => recvCount++);
            wise.PacketFactory.Instance.Add(new wise.Topic(1, 1, 1), () => { return(new PacketSample()); });
            wise.Detail.Protocol protocol = new wise.Detail.Protocol();

            PacketSample ps = new PacketSample();
            MemoryStream ms = new MemoryStream();

            protocol.OnSend(ps, ms);

            ms.Position = 0;

            protocol.OnRecv(ms.GetBuffer(), (int)(ms.Length - 5));
            Assert.IsTrue(recvCount == 0);

            MemoryStream rs = new MemoryStream();

            rs.Write(ms.GetBuffer(), (int)(ms.Length - 5), 5);
            rs.Write(ms.GetBuffer(), 0, (int)ms.Length);

            protocol.OnRecv(rs.GetBuffer(), (int)rs.Length);
            Assert.IsTrue(recvCount == 2);
        }
Esempio n. 2
0
        public void TestProtocolCipherModifier()
        {
            int recvCount = 0;

            PacketCipher pc = null;

            wise.Network.Instance.Subscribe(
                new PacketCipher(),
                (m) => {
                recvCount++;
                wise.Network.Logger.Info(string.Format("{0}", m.hello));
                pc = m;
            }
                );
            wise.PacketFactory.Instance.Add(new wise.Topic(1, 1, 4), () => { return(new PacketCipher()); });
            wise.Detail.Protocol protocol = new wise.Detail.Protocol();

            PacketCipher ps = new PacketCipher();
            MemoryStream ms = new MemoryStream();

            ps.value = 77;

            for (int i = 0; i < 128; ++i)
            {
                ps.hello = ps.hello.Insert(0, "Hello ");
            }

            for (int i = 0; i < 2048; ++i)
            {
                ms.Position = 0;
                protocol.OnSend(ps, ms);
                // protocol.OnSend(ps, ms);

                var result = protocol.OnRecv(ms.GetBuffer(), (int)ms.Length);
                Assert.IsTrue(result);
            }

            Assert.IsTrue(pc != null);
            Assert.IsTrue(pc.value == ps.value);
            Assert.IsTrue(pc.hello == ps.hello);

            // ms.Position = 0;
            // protocol.OnSend(ps, ms);
            // protocol.OnSend(ps, ms);

            // result = protocol.OnRecv(ms.GetBuffer(), (int)ms.Length);
            // Assert.IsTrue(result);
        }
Esempio n. 3
0
        public void TestProtocolChecksumModifier()
        {
            int recvCount = 0;

            wise.Network.Instance.Subscribe(new PacketChecksum(), (m) => recvCount++);
            wise.PacketFactory.Instance.Add(new wise.Topic(1, 1, 3), () => { return(new PacketChecksum()); });
            wise.Detail.Protocol protocol = new wise.Detail.Protocol();

            PacketChecksum ps = new PacketChecksum();
            MemoryStream   ms = new MemoryStream();

            for (int i = 0; i < 1024; ++i)
            {
                ms.Position = 0;
                protocol.OnSend(ps, ms);

                var result = protocol.OnRecv(ms.GetBuffer(), (int)ms.Length);

                Assert.IsTrue(!!result);
            }
        }