public void PingPackageDeserializationTest()
        {
            PingPackage expected = new PingPackage
            {
                Value = 10
            };

            var buffer = expected.ToByteArray();

            PingPackage       actual      = new PingPackage();
            int               len         = 0;
            ClientPackageType packageType = ClientPackageType.None;

            using (var stream = new MemoryStream(buffer))
            {
                using (var reader = new BinaryReader(stream))
                {
                    len         = reader.ReadInt32();
                    packageType = (ClientPackageType)reader.ReadByte();
                    actual.FromByteArray(reader.ReadBytes(len - 1));
                }
            }

            Assert.AreEqual(5, len);
            Assert.AreEqual(ClientPackageType.Ping, packageType);
            Assert.AreEqual(9, buffer.Length);
            Assert.AreEqual(expected.Value, actual.Value);
        }
        public void PingSerializationTest()
        {
            var packageBase = new PingPackage
            {
                Value = 10
            };

            var buffer = packageBase.ToByteArray();

            Assert.AreEqual(9, buffer.Length);
        }
        public void GetPingPackageTest()
        {
            var package = new PingPackage {
                Value = 10
            };
            var data = package.ToByteArray();

            ClientPackage clientPackage = _factory.GetNextPackage(data);

            Assert.NotNull(clientPackage);
            Assert.AreEqual(data, clientPackage.ToByteArray());
            Assert.AreEqual(package.Type, clientPackage.Type);
        }
Exemple #4
0
        private void SendPacket()
        {
            PingPackage pingPackage = new PingPackage
            {
                Value = value
            };

            var arr = pingPackage.ToByteArray();

            _stream.Write(arr, 0, arr.Length);
            _stream.BeginWrite(arr, 0, arr.Length,
                               ar =>
            {
                _stream.EndWrite(ar);
                Debug.Log("Date Sendet!");
            },
                               _stream);
        }