Beispiel #1
0
        /// <summary>
        /// Returns true if the message data is complete
        /// out data is the internal data, header is stripped
        /// </summary>
        /// <param name="msg">byte array from the network stream</param>
        /// <param name="internalDataAsBytes">output when available</param>
        /// <returns>true if data is available on the 'out'</returns>
        public static bool ReceiveData(string owner_id, byte[] msg, out byte[] internalDataAsBytes)
        {
            //This could have its own thread....
            timeoutHandle();

            //convert the data
            NetDataEnvelope env = new NetDataEnvelope(msg);

            // see if multipart or not
            // handle multipart buffer
            if (env.PartTotal == 1)
            {
                // is not multipart
                // return the internal data straight from the message
                internalDataAsBytes = env.DataInsideEnvelope;
                return(true);
            }
            else if (env.PartTotal > 1)
            {
                DataGroup group = DataGroup.Combine(owner_id, env.Ident, dataGroups);


                if (group == null)
                {
                    dataGroups.Add(new DataGroup(env, owner_id));
                    internalDataAsBytes = new byte[0];
                    return(false);
                }
                else
                {
                    if (group.addPart(env))
                    {
                        // is done
                        internalDataAsBytes = group.AllInternalData; // Set the return data
                        dataGroups.Remove(group);                    // We are done with this group, remove it
                        return(true);                                // return true so system knows to read data
                    }
                    else
                    {
                        // Update recTime so does not timeout
                        group.recTime = DateTime.Now;
                    }
                    internalDataAsBytes = new byte[0];
                    return(false);
                }
            }

            //ERROR part total less than 1 ???
            internalDataAsBytes = new byte[0];
            return(false);
        }