Example #1
0
        public void ParseBytesBuffer_Test2()
        {
            var parser = new AleStreamParser();
            var bytes1 = new byte[] { 0x00, 0x09, 0x01, 0x02, 0x03, 0x03 /* 前半部分 */ };
            var bytes2 = new byte[] { 0x01, 0x04, 0x05, 0x05, 0xAA /* 后半部分 */ };

            var frames = parser.ParseTcpStream(bytes1, bytes1.Length);

            Assert.AreEqual(frames.Count, 0);

            frames = parser.ParseTcpStream(bytes2, bytes2.Length);
            Assert.AreEqual(frames.Count, 1);
        }
Example #2
0
        public void ParseBytesBuffer_Test5()
        {
            var parser = new AleStreamParser();
            var bytes  = new byte[] { 0xFF, 0xFF, 0x01, 0x02, 0x03, 0x03, 0x01, 0x04, 0x05, 0x05, 0xAA };

            var frames = parser.ParseTcpStream(bytes, bytes.Length);

            Assert.AreEqual(frames.Count, 1);
        }
Example #3
0
        public void ParseBytesBuffer_Test11()
        {
            var parser = new AleStreamParser();
            var bytes  = new byte[] { 0x00 /*无效字节*/, 0x00, 0x08, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A };

            var frames = parser.ParseTcpStream(bytes, bytes.Length);

            Assert.AreEqual(frames.Count, 1);
        }
Example #4
0
        public void ParseBytesBuffer_Test3()
        {
            var parser = new AleStreamParser();
            var bytes  = new byte[] { 0x00, 0x09, 0x01, 0x02, 0x03, 0x03, 0x01, 0x04, 0x05, 0x05, 0xA1, /*第一帧*/
                                      0x00, 0x09, 0x01, 0x02, 0x03, 0x03, 0x01, 0x04, 0x05, 0x05, 0xA2  /*第二帧*/
            };

            var frames = parser.ParseTcpStream(bytes, bytes.Length);

            Assert.AreEqual(frames.Count, 2);
        }
Example #5
0
        private void HandleDataReceived(byte[] buffer, int bytesRead)
        {
            try
            {
                var aleFrameBytes = _streamPaser.ParseTcpStream(buffer, bytesRead);

                aleFrameBytes.ForEach(p =>
                {
                    var aleFrame = AleFrame.Parse(p);
                    this.Observer.OnAleFrameArrival(this, aleFrame);
                });
            }
            catch (System.Exception ex)
            {
                LogUtility.Error(ex.ToString());
                // 方式1:异常全部忽略,继续异步接收。
                // 方式2:断开连接。
                //this.Disconnect();
            }
        }