public void GetPongPackageTest()
        {
            var data = _pongPackage.ToByteArray();

            ServerPackage package = _factory.GetNextPackage(data);

            Assert.NotNull(package);
            Assert.AreEqual(data, package.ToByteArray());
            Assert.AreEqual(_pongPackage.Type, package.Type);
        }
        public void GetSetRoomPackageTest()
        {
            var data = _setRoomPackage.ToByteArray();

            ServerPackage clientPackage = _factory.GetNextPackage(data);

            Assert.NotNull(clientPackage);
            Assert.AreEqual(data, clientPackage.ToByteArray());
            Assert.AreEqual(_setRoomPackage.Type, clientPackage.Type);
        }
        public void UpdatePositionsPackageTest()
        {
            var data = _updatePositionsPackage.ToByteArray();

            ServerPackage package = _factory.GetNextPackage(data);

            Assert.NotNull(package);
            Assert.AreEqual(_updatePositionsPackage.Type, package.Type);
            Assert.AreEqual(_updatePositionsPackage.Units.Length, ((UpdatePositionsPackage)package).Units.Length);
            Assert.AreEqual(data, package.ToByteArray());
        }
        public void GetAcceptLoginPackageTest()
        {
            var data = _acceptLoginPackage.ToByteArray();

            ServerPackage package = _factory.GetNextPackage(data);

            Assert.NotNull(package);
            Assert.AreEqual(data, package.ToByteArray());
            Assert.AreEqual(_acceptLoginPackage.Type, package.Type);
            Assert.AreEqual(_acceptLoginPackage.ClientId, ((AcceptLoginPackage)package).ClientId);
        }
Пример #5
0
        public async void SendPackage(ServerPackage package)
        {
            var data = package.ToByteArray();

            try
            {
                await _stream.WriteAsync(data, 0, data.Length, _tokenSource.Token);
            }
            catch (IOException)
            {
                Logger.Info($"Disconnect client {ClientId} by exception");
                Disconnect();
            }
            catch (TaskCanceledException)
            {
                Logger.Info($"Disconnect client {ClientId} by exception");
                Disconnect();
            }
        }