コード例 #1
0
ファイル: CryptPack.cs プロジェクト: tallyon/NETLIB
 /// <summary>
 ///     Initialize the CryptoPack
 /// </summary>
 /// <param name="basePack">BasePack that will be copy</param>
 public CryptPack(BasePack basePack)
     : base(basePack)
 {
     this.encrypted     = GetBool(1);
     this.readPosition  = CID_POSITION + sizeof(int);
     this.writePosition = CID_POSITION + sizeof(int);
 }
コード例 #2
0
 public BaseAction(int ActionID, HttpGet HttpGet)
 {
     httpGet   = HttpGet;
     _actionID = ActionID;
     basePack  = new BasePack();
     baseLog   = new BaseLog(httpGet.param);
 }
コード例 #3
0
ファイル: CryptPack.cs プロジェクト: tallyon/NETLIB
 /// <summary>
 ///     Initialize the CryptoPack
 /// </summary>
 /// <param name="basePack">BasePack that will be copy</param>
 public CryptPack(BasePack basePack)
     : base(basePack)
 {
     this.encrypted = GetBool(1);
     this.readPosition = CID_POSITION + sizeof(int);
     this.writePosition = CID_POSITION + sizeof(int);
 }
コード例 #4
0
 /// <summary>
 /// Send a pack
 /// </summary>
 /// <param name="pack">Pack to be sender</param>
 /// <param name="host_name">Host's name</param>
 /// <param name="port">Host's port</param>
 public void SendPack(BasePack pack, string host_name, int port)
 {
     if (isEnable)
     {
         sender.Send(pack.Buffer, pack.Buffer.Length);
     }
     else
     {
         throw new ConnectionClosedException("Connection closed!");
     }
 }
コード例 #5
0
        public void PutStringTestAndGetStringTest()
        {
            // Arrange
            string   stringPut = "Test string.";
            BasePack basePack  = new BasePack();

            // Act
            basePack.PutString(stringPut);
            string stringGet = basePack.GetString();

            // Assert
            Assert.AreEqual(stringPut, stringGet);
        }
コード例 #6
0
        public void PutFloatAtTheBeginningAndGetFloatFromTheBeginningTest()
        {
            // Arrange
            float    floatPut = 123.4f;
            BasePack basePack = new BasePack();

            // Act
            basePack.PutFloat(floatPut);
            float floatGet = basePack.GetFloat();

            // Assert
            Assert.AreEqual(floatPut, floatGet);
        }
コード例 #7
0
        public void PutBoolAtTheBeginningAndGetBoolFromTheBeginningTest()
        {
            // Arrange
            bool     boolPut  = true;
            BasePack basePack = new BasePack();

            // Act
            basePack.PutBool(boolPut);
            bool boolGet = basePack.GetBool();

            // Assert
            Assert.AreEqual(boolPut, boolGet);
        }
コード例 #8
0
        public void PutByteAtTheBeginningAndGetByteFromTheBeginningTest()
        {
            // Arrange
            byte     bytePut  = 7;
            BasePack basePack = new BasePack();

            // Act
            basePack.PutByte(bytePut);
            byte byteGet = basePack.GetByte();

            // Assert
            Assert.AreEqual(bytePut, byteGet);
        }
コード例 #9
0
        public void PutCharAtTheBeginningAndGetCharFromTheBeginningTest()
        {
            // Arrange
            char     charPut  = 'a';
            BasePack basePack = new BasePack();

            // Act
            basePack.PutChar(charPut);
            char charGet = basePack.GetChar();

            // Assert
            Assert.AreEqual(charPut, charGet);
        }
コード例 #10
0
ファイル: BasePackTests.cs プロジェクト: tallyon/NETLIB
        public void PutDoubleAtTheBeginningAndGetDoubleFromTheBeginningTest()
        {
            // Arrange
            double doublePut = 123.4;
            BasePack basePack = new BasePack();

            // Act
            basePack.PutDouble(doublePut);
            double doubleGet = basePack.GetDouble();

            // Assert
            Assert.AreEqual(doublePut, doubleGet);
        }
コード例 #11
0
ファイル: BasePackTests.cs プロジェクト: tallyon/NETLIB
        public void PutCharAtTheBeginningAndGetCharFromTheBeginningTest()
        {
            // Arrange
            char charPut = 'a';
            BasePack basePack = new BasePack();

            // Act
            basePack.PutChar(charPut);
            char charGet = basePack.GetChar();

            // Assert
            Assert.AreEqual(charPut, charGet);
        }
コード例 #12
0
ファイル: BasePackTests.cs プロジェクト: tallyon/NETLIB
        public void PutByteAtTheBeginningAndGetByteFromTheBeginningTest()
        {
            // Arrange
            byte bytePut = 7;
            BasePack basePack = new BasePack();

            // Act
            basePack.PutByte(bytePut);
            byte byteGet = basePack.GetByte();

            // Assert
            Assert.AreEqual(bytePut, byteGet);
        }
コード例 #13
0
ファイル: BasePackTests.cs プロジェクト: tallyon/NETLIB
        public void PutBoolAtTheBeginningAndGetBoolFromTheBeginningTest()
        {
            // Arrange
            bool boolPut = true;
            BasePack basePack = new BasePack();

            // Act
            basePack.PutBool(boolPut);
            bool boolGet = basePack.GetBool();

            // Assert
            Assert.AreEqual(boolPut, boolGet);
        }
コード例 #14
0
        public void PutIntAtTheBeginningAndGetIntFromBeginningTest()
        {
            // Arrange
            int      intPut   = 123;
            BasePack basePack = new BasePack();

            // Act
            basePack.PutInt(intPut);
            int intGet = basePack.GetInt();

            // Assert
            Assert.AreEqual(intPut, intGet);
        }
コード例 #15
0
        public void PutDoubleAtTheBeginningAndGetDoubleFromTheBeginningTest()
        {
            // Arrange
            double   doublePut = 123.4;
            BasePack basePack  = new BasePack();

            // Act
            basePack.PutDouble(doublePut);
            double doubleGet = basePack.GetDouble();

            // Assert
            Assert.AreEqual(doublePut, doubleGet);
        }
コード例 #16
0
        public void ReadTestAreBuffersEqual()
        {
            // Arrange
            BasePack basePack = new BasePack();

            byte[] buff = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
            basePack.Write(buff, 0, buff.Length);

            // Act
            byte[] buffRead = new byte[buff.Length];
            basePack.Read(buffRead, 0, buffRead.Length);

            // Assert
            CollectionAssert.AreEqual(buff, buffRead);
        }
コード例 #17
0
ファイル: BasePackTests.cs プロジェクト: tallyon/NETLIB
        public void ConversionFromByteArrayToBasePackTest()
        {
            // Arrange
            BasePack basePack = new BasePack();
            byte[] byteArray = new byte[BasePack.packSize];
            for (int i = 0; i < byteArray.Length; i++)
                byteArray[i] = (byte)(i % 256);

            // Act
            basePack = byteArray;

            // Assert
            for (int i = 0; i < byteArray.Length; i++)
                Assert.AreEqual(byteArray[i], basePack.Buffer[i]);
        }
コード例 #18
0
        /// <summary>
        /// Send a pack
        /// </summary>
        /// <param name="pack">Pack to be sender</param>
        /// <param name="ip">Address to send</param>
        public override void SendPack(BasePack pack, IPEndPoint ip = null)
        {
            if (isEnable)
            {
                if (ip == null)
                {
                    throw new ArgumentNullException("IP cant be null!");
                }

                sender.Send(pack.Buffer, pack.Buffer.Length, ip);
            }
            else
            {
                throw new ConnectionClosedException("Connection closed!");
            }
        }
コード例 #19
0
 /// <summary>
 /// Send a pack
 /// </summary>
 /// <param name="pack">Pack to be sender</param>
 ///  <param name="ip">Optional parameter used only by UDP protocol</param>
 public override void SendPack(BasePack pack, IPEndPoint ip = null)
 {
     if (isEnable)
     {
         try
         {
             input.Write(pack.Buffer, 0, pack.Buffer.Length);
         }
         catch (IOException e)
         {
             OnConnectionClosedCall();
             Console.WriteLine(e.Message);
             Console.WriteLine("Connection closed! Host do not answer.");
         }
     }
 }
コード例 #20
0
ファイル: UDPPublisher.cs プロジェクト: tallyon/NETLIB
        /// <summary>
        /// Send a pack 
        /// </summary>
        /// <param name="pack">Pack to be sender</param>
        /// <param name="ip">Address to send</param>
        public override void SendPack(BasePack pack, IPEndPoint ip = null)
        {
            if (isEnable)
            {
                if (ip == null)
                {
                    throw new ArgumentNullException("IP cant be null!");
                }

                sender.Send(pack.Buffer, pack.Buffer.Length, ip);
            }
            else
            {
                throw new ConnectionClosedException("Connection closed!");
            }
        }
コード例 #21
0
ファイル: TCPPublisher.cs プロジェクト: tallyon/NETLIB
 /// <summary>
 /// Send a pack 
 /// </summary>
 /// <param name="pack">Pack to be sender</param>
 ///  <param name="ip">Optional parameter used only by UDP protocol</param>
 public override void SendPack(BasePack pack, IPEndPoint ip = null)
 {
     if (isEnable)
     {
         try
         {
             input.Write(pack.Buffer, 0, pack.Buffer.Length);
         }
         catch (IOException e)
         {
             OnConnectionClosedCall();
             Console.WriteLine(e.Message);
             Console.WriteLine("Connection closed! Host do not answer.");
         }
     }
 }
コード例 #22
0
        public void WriteTestAreBuffersEqual()
        {
            // Arrange
            BasePack basePack = new BasePack();

            byte[] buff = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

            // Act
            basePack.Write(buff, 0, buff.Length);

            // Assert - note that BasePack's buffer[0] is Pack's header, so written buffer is shifted by 1 to the right
            byte[] buffWritten = basePack.Buffer;
            for (int i = 0; i < buff.Length; i++)
            {
                Assert.AreEqual(buff[i], buffWritten[i + 1]);
            }
        }
コード例 #23
0
        public void ConversionFromByteArrayToBasePackTest()
        {
            // Arrange
            BasePack basePack = new BasePack();

            byte[] byteArray = new byte[BasePack.packSize];
            for (int i = 0; i < byteArray.Length; i++)
            {
                byteArray[i] = (byte)(i % 256);
            }

            // Act
            basePack = byteArray;

            // Assert
            for (int i = 0; i < byteArray.Length; i++)
            {
                Assert.AreEqual(byteArray[i], basePack.Buffer[i]);
            }
        }
コード例 #24
0
        /// <summary>
        /// Publish packs in pack_queue
        /// </summary>
        /// <exception cref="Exception"></exception>
        protected override void Publish()
        {
            byte[] buffer;

            while (isInputEnabled)
            {
                IPEndPoint info = null;
                try
                {
                    buffer = listener.Receive(ref info);
                    BasePack.PutString(buffer, info.Address.ToString(), 1);
                    pack_queue.Enqueue(buffer);
                    manualEvent.Set();
                }
                catch (Exception e)
                {
                    OnConnectionClosedCall();
                    Console.WriteLine(e.Message);
                    Console.WriteLine("Connection closed! Host do not answer.");
                }
            }
        }
コード例 #25
0
ファイル: BasePackTests.cs プロジェクト: tallyon/NETLIB
        public void PutIntAtTheBeginningAndGetIntFromBeginningTest()
        {
            // Arrange
            int intPut = 123;
            BasePack basePack = new BasePack();

            // Act
            basePack.PutInt(intPut);
            int intGet = basePack.GetInt();

            // Assert
            Assert.AreEqual(intPut, intGet);
        }
コード例 #26
0
 public override UDPPack PackFactory(BasePack pack)
 {
     return(new UDPPack(pack));
 }
コード例 #27
0
ファイル: CryptIOPackHandler.cs プロジェクト: tallyon/NETLIB
 public override CryptPack PackFactory(BasePack pack)
 {
     return(new CryptPack(pack));
 }
コード例 #28
0
 public UDPPack(BasePack basePack) : base(basePack)
 {
     this.readPosition += sizeof(int) + 15;
 }
コード例 #29
0
ファイル: BasePackTests.cs プロジェクト: tallyon/NETLIB
        public void PutStringTestAndGetStringTest()
        {
            // Arrange
            string stringPut = "Test string.";
            BasePack basePack = new BasePack();

            // Act
            basePack.PutString(stringPut);
            string stringGet = basePack.GetString();

            // Assert
            Assert.AreEqual(stringPut, stringGet);
        }
コード例 #30
0
ファイル: BasePackTests.cs プロジェクト: tallyon/NETLIB
        public void ReadTestAreBuffersEqual()
        {
            // Arrange
            BasePack basePack = new BasePack();
            byte[] buff = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
            basePack.Write(buff, 0, buff.Length);

            // Act
            byte[] buffRead = new byte[buff.Length];
            basePack.Read(buffRead, 0, buffRead.Length);

            // Assert
            CollectionAssert.AreEqual(buff, buffRead);
        }
コード例 #31
0
ファイル: BasePackTests.cs プロジェクト: tallyon/NETLIB
        public void WriteTestAreBuffersEqual()
        {
            // Arrange
            BasePack basePack = new BasePack();
            byte[] buff = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

            // Act
            basePack.Write(buff, 0, buff.Length);

            // Assert - note that BasePack's buffer[0] is Pack's header, so written buffer is shifted by 1 to the right
            byte[] buffWritten = basePack.Buffer;
            for (int i = 0; i < buff.Length; i++)
                Assert.AreEqual(buff[i], buffWritten[i + 1]);
        }
コード例 #32
0
ファイル: BasePackTests.cs プロジェクト: tallyon/NETLIB
        public void PutFloatAtTheBeginningAndGetFloatFromTheBeginningTest()
        {
            // Arrange
            float floatPut = 123.4f;
            BasePack basePack = new BasePack();

            // Act
            basePack.PutFloat(floatPut);
            float floatGet = basePack.GetFloat();

            // Assert
            Assert.AreEqual(floatPut, floatGet);
        }
コード例 #33
0
ファイル: UDPPublisher.cs プロジェクト: tallyon/NETLIB
 /// <summary>
 /// Send a pack 
 /// </summary>
 /// <param name="pack">Pack to be sender</param>
 /// <param name="host_name">Host's name</param>
 /// <param name="port">Host's port</param>
 public void SendPack(BasePack pack, string host_name, int port)
 {
     if (isEnable)
     {
         sender.Send(pack.Buffer, pack.Buffer.Length);
     }
     else
     {
         throw new ConnectionClosedException("Connection closed!");
     }
 }
コード例 #34
0
ファイル: Publisher.cs プロジェクト: tallyon/NETLIB
 /// <summary>
 /// Send a pack 
 /// </summary>
 /// <param name="pack">Pack to be sender</param>
 ///  <param name="ip">Optional parameter used only by UDP protocol</param>
 public abstract void SendPack(BasePack pack, IPEndPoint ip = null);
コード例 #35
0
ファイル: UDPPack.cs プロジェクト: tallyon/NETLIB
 public UDPPack(BasePack basePack)
     : base(basePack)
 {
     this.readPosition += sizeof(int) + 15;
 }