Esempio n. 1
0
        public bool SendEntity(SendPacket entity, ISendDelivery delivery)
        {
            int    cursor = 0;
            int    total  = entity.GetLength();
            Stream stream = entity.GetInputStream();
            int    count;

            try
            {
                while ((count = stream.Read(mOutBuffer, 0, mBufferSize)) != -1)
                {
                    // Write
                    mSocket.Send(mOutBuffer, 0, count, SocketFlags.None);
                    cursor += count;

                    // Post progress
                    delivery.PostSendProgress(entity, total, cursor);
                }
                return(true);
            }
            catch (IOException e)
            {
                Console.WriteLine(e.Message);
            }
            finally
            {
                CloseStream(stream);
            }
            return(false);
        }