Esempio n. 1
0
        public void Read(Stream r)
        {
            Length headLen = new Length(0);

            headLen.Read(r);
            int _headLen = (int)(ulong)headLen;

            byte[] headBuf = new byte[_headLen];
            r.Read(headBuf, 0, _headLen);
            Head = System.Text.Encoding.Default.GetString(headBuf);
            Length count_l = new Length(0);

            count_l.Read(r);
            var count = (int)count_l;

            for (int i = 0; i < count; i++)
            {
                Length id_l = new Length(0);
                id_l.Read(r);
                ulong  id           = (ulong)id_l;
                Length queueCount_l = new Length(0);
                queueCount_l.Read(r);
                int queueCount = (int)queueCount_l;
                var frames     = new FrameMessage[queueCount];
                for (int j = 0; j < queueCount; j++)
                {
                    var msg = new FrameMessage();
                    msg.Read(r);
                    frames[j] = msg;
                }
                AppendQueue(id, frames);
            }
        }
Esempio n. 2
0
        public void Init()
        {
            DateTime now = DateTime.Now;

            Console.WriteLine("Start Test FrameMessage!");
            msg = new FrameMessage("Say", System.Text.Encoding.Default.GetBytes("Hello"), (ulong)now.Ticks);
        }
Esempio n. 3
0
 public bool Equals(FrameMessage msg)
 {
     if (TimeStamp != msg.TimeStamp)
     {
         return(false);
     }
     return(base.Equals(msg));
 }
Esempio n. 4
0
        public void Recv(int time, Action <MessageType, Message, FrameMessage, FrameQueuesMessage> cb)
        {
            if (m_socket.Poll(time, SelectMode.SelectRead))
            {
                if (m_recvStream == null)
                {
                    m_recvStream = new NetworkStream(m_socket);
                }
                MessageType t = new MessageType(0);
                t.Read(m_recvStream);
                switch ((byte)t)
                {
                case MessageType.Normal:
                    Message msg = new Message();
                    msg.Read(m_recvStream);
                    cb(t, msg, null, null);
                    break;

                case MessageType.Frame:
                    FrameMessage frame = new FrameMessage();
                    frame.Read(m_recvStream);
                    cb(t, null, frame, null);
                    break;

                case MessageType.FrameQueues:
                    FrameQueuesMessage queues = new FrameQueuesMessage();
                    queues.Read(m_recvStream);
                    cb(t, null, null, queues);
                    break;

                default:
                    break;
                }
            }
            else
            {
                Thread.Sleep(time);
            }
        }
Esempio n. 5
0
        public void TestReadWrite()
        {
            MemoryStream ms    = new MemoryStream();
            FrameMessage _msg  = new FrameMessage();
            DateTime     now   = DateTime.Now;
            FrameMessage aMsg  = new FrameMessage("Spell", System.Text.Encoding.Default.GetBytes("F**k"), (ulong)now.Ticks);
            FrameMessage _aMsg = new FrameMessage();

            try {
                msg.Write(ms);
                aMsg.Write(ms);
                ms.Position = 0;
                _msg.Read(ms);
                _aMsg.Read(ms);
            } catch (System.Exception e) {
                Console.WriteLine("Exception");
                Console.WriteLine(e);
            }
            Assert.AreEqual(msg.ToString(), _msg.ToString());
            Assert.AreEqual(aMsg.ToString(), _aMsg.ToString());
            Assert.Inconclusive("Test ReadWrite");
        }
Esempio n. 6
0
 public string SendFrame(FrameMessage msg)
 {
     return(send(MessageType.Frame, msg));
 }