Exemplo n.º 1
0
        /// <summary>
        /// Inicializa uma nova instância da classe <see cref="Spartacus.Net.Packet"/>.
        /// </summary>
        /// <param name="p_type">Tipo do Pacote.</param>
        /// <param name="p_data">Dados do Pacote.</param>
        public Packet(Spartacus.Net.PacketType p_type, byte[] p_data)
        {
            this.v_encoding = new System.Text.ASCIIEncoding();

            this.v_type       = p_type;
            this.v_sequence   = 0;
            this.v_numpackets = 1;
            this.v_data       = p_data;

            this.BuildBuffer();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Inicializa uma nova instância da classe <see cref="Spartacus.Net.Packet"/>.
        /// </summary>
        /// <param name="p_type">Tipo do Pacote.</param>
        /// <param name="p_sequence">Sequência atual do Pacote dentro da Mensagem.</param>
        /// <param name="p_numpackets">Número total de pacotes da Mensagem.</param>
        /// <param name="p_data">Dados do Pacote.</param>
        public Packet(Spartacus.Net.PacketType p_type, int p_sequence, int p_numpackets, string p_data)
        {
            this.v_encoding = new System.Text.ASCIIEncoding();

            this.v_type       = p_type;
            this.v_sequence   = p_sequence;
            this.v_numpackets = p_numpackets;
            this.v_data       = this.v_encoding.GetBytes(p_data);

            this.BuildBuffer();
        }
Exemplo n.º 3
0
        /// <summary>
        /// Constrói um Pacote a partir dos dados recebidos.
        /// Usado para receber um Pacote.
        /// </summary>
        private void ParseBuffer()
        {
            byte[] v_tmpbuffer;
            string v_tmp;

            if (this.v_buffer.Length < 25)
            {
                throw new Spartacus.Net.Exception("Pacote muito pequeno.");
            }

            v_tmpbuffer = new byte[25];
            System.Array.Copy(this.v_buffer, 0, v_tmpbuffer, 0, v_tmpbuffer.Length);
            v_tmp = this.v_encoding.GetString(v_tmpbuffer);

            // tipo do pacote
            switch (v_tmp.Substring(0, 5))
            {
            case "DATA ":
                this.v_type = Spartacus.Net.PacketType.DATA;
                break;

            case "ACK  ":
                this.v_type = Spartacus.Net.PacketType.ACK;
                break;

            case "NACK ":
                this.v_type = Spartacus.Net.PacketType.NACK;
                break;

            case "ERROR":
                this.v_type = Spartacus.Net.PacketType.ERROR;
                break;

            case "WARNG":
                this.v_type = Spartacus.Net.PacketType.WARNING;
                break;

            case "FILE ":
                this.v_type = Spartacus.Net.PacketType.FILE;
                break;

            default:
                throw new Spartacus.Net.Exception("Tipo de pacote [{0}] não existe.", v_tmp.Substring(0, 5));
            }

            // sequencia
            this.v_sequence = System.Int32.Parse(v_tmp.Substring(5, 10));

            // numero total de pacotes
            this.v_numpackets = System.Int32.Parse(v_tmp.Substring(15, 10));

            // dados
            if (this.v_buffer.Length > 25)
            {
                this.v_data = new byte[this.v_buffer.Length - 25];
                System.Array.Copy(this.v_buffer, 25, this.v_data, 0, this.v_data.Length);
            }
            else
            {
                this.v_data = null;
            }
        }