Example #1
0
        public void OneByte()
        {
            byte[] sourceArray = @"
F1E2D3C4 00000000 00
000002 000186A0 0000
0002 00000004 000000
00 00000000 00000000
00000000".LogToArray();

            TcpWriter msg = new TcpWriter(13);

            foreach (var b in sourceArray)
            {
                msg.Write(b);
            }

            List <byte[]> blocks = new List <byte[]>(msg.Build());

            Assert.AreEqual(5, blocks.Count);
            Assert.AreEqual("00000009 F1E2D3C4 00000000 00".LogToArray(), blocks[0]);
            Assert.AreEqual("00000009 000002 000186A0 0000".LogToArray(), blocks[1]);
            Assert.AreEqual("00000009 0002 00000004 000000".LogToArray(), blocks[2]);
            Assert.AreEqual("00000009 00 00000000 00000000".LogToArray(), blocks[3]);
            Assert.AreEqual("80000004 00000000".LogToArray(), blocks[4]);
        }
Example #2
0
        public void Short2()
        {
            TcpWriter msg = new TcpWriter(13);

            msg.Write("F1E2D3C4 00000000 00".LogToArray());

            List <byte[]> blocks = new List <byte[]>(msg.Build());

            Assert.AreEqual(1, blocks.Count);
            Assert.AreEqual("80000009 F1E2D3C4 00000000 00".LogToArray(), blocks[0]);
        }
Example #3
0
        public void AllBytes()
        {
            TcpWriter msg = new TcpWriter(13);

            msg.Write("F1E2D3C4 00000000 00000002 000186A0 00000002 00000004 00000000 00000000 00000000 00000000".LogToArray());

            List <byte[]> blocks = new List <byte[]>(msg.Build());

            Assert.AreEqual(5, blocks.Count);
            Assert.AreEqual("00000009 F1E2D3C4 00000000 00".LogToArray(), blocks[0]);
            Assert.AreEqual("00000009 000002 000186A0 0000".LogToArray(), blocks[1]);
            Assert.AreEqual("00000009 0002 00000004 000000".LogToArray(), blocks[2]);
            Assert.AreEqual("00000009 00 00000000 00000000".LogToArray(), blocks[3]);
            Assert.AreEqual("80000004 00000000".LogToArray(), blocks[4]);
        }
Example #4
0
        private void BuildMessage(object state)
        {
            LinkedList<byte[]> blocks;
            try
            {
                TcpWriter tw = new TcpWriter(_maxBlock);
                _sendingTicket.BuildRpcMessage(tw);
                blocks = tw.Build();
            }
            catch(Exception ex)
            {
                Log.Debug("TCP message not builded (xid:{0}) reason: {1}", _sendingTicket.Xid, ex);
                lock(_sync)
                    _handlers.Remove(_sendingTicket.Xid);
                _sendingTicket.Except(ex);
                OnSend();
                return;
            }

            BeginReceive();
            Log.Debug("Begin sending TCP message (xid:{0})", _sendingTicket.Xid);
            _client.AsyncWrite(blocks, OnBlocksWrited);
        }