Beispiel #1
0
        /// <summary>
        /// Read a single message
        /// </summary>
        protected override byte[] ReadMessage()
        {
            // Check for an open connection
            var port = this.tcpClient;

            if (port == null)
            {
                return(null);
            }

            // Try to read the message
            var data = new byte[16];

            while (true)
            {
                // Read a potential opcode

                Read(port, data, 0, 1);
                if (Message.IsOpcode(data[0]))
                {
                    break;
                }
            }

            // Now read further data
            Read(port, data, 1, 1); // Read at least the second byte

            var length = Message.GetMessageLength(data);

            if (length > 2)
            {
                // Read remaining data
                Read(port, data, 2, length - 2);
            }

            return(data);
        }
        /// <summary>
        /// Read a single message
        /// </summary>
        protected override byte[] ReadMessage()
        {
            // Check for an open connection
            var port = this.udpSocket;

            if (port == null)
            {
                return(null);
            }

            // Try to read the message
            var data = new byte[16];

            while (true)
            {
                // Read a potential opcode
                udpSocket.Receive(data);
                if (Message.IsOpcode(data[0]))
                {
                    break;
                }

                if (data[0] == 113)
                {
                }
            }

            /*var length = Message.GetMessageLength(data);
             * if (length > 2)
             * {
             *  // Read remaining data
             *  Read(port, data, 2, length - 2);
             * }*/

            return(data);
        }