Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8002303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:19:15+00:00 2026-06-04T16:19:15+00:00

Text files seem to be alright. Here is the code that is used to

  • 0

Text files seem to be alright.
Here is the code that is used to send the files:

System.IO.FileStream stream = new System.IO.FileStream(file, System.IO.FileMode.Open, System.IO.FileAccess.Read);
System.IO.BinaryReader reader = new System.IO.BinaryReader(stream);
double done = 0;
double tot = info.Length;
double chunk = 8096;

while (done < tot)
{
    if (chunk > tot - done)
    {
        chunk = tot - done;
    }
    Byte[] buffer = new Byte[(int)chunk];
    reader.Read(buffer,(int)done,(int)chunk);
    sock.Send(buffer);
    done += chunk;
    statusTxt.Text = Math.Round(done / tot * 100, 2).ToString() + "%";
}

And the code to receive the files is very similar:

private void ReceiveFile(string file, Socket sock,double size)
{
    while (done < size)
        {
            if (chunk > (size - done))
            {
                chunk = size - done;
            }
            Byte[] buffer = new Byte[(int)chunk];

            int count = sock.Receive(buffer);
            writer.Write(buffer);
            done += count;

            this.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, (Action)delegate()
            {
                foreach (TextBlock block in files.Items)
                {
                    if (block.Tag.ToString() == file)
                    {
                        block.Text = "Uploading " + file + "... 0% ("+done.ToString()+"/" + size.ToString() + ")";
                    }
                }
            });
        }
        writer.Flush();
        writer.Close();
    }

I have seen many posts concerning image artifacts, but all the problems dealt with bytes being encoded to text. I believe that I’ve avoided that problem. I use Byte arrays during the entire process and I keep track of how many bytes are being read, but the images still end up corrupted. I checked the files, and they contain the same exact amount of bytes on the client and server, so SOMETHING is going on the server, but its just not correct. Anything wrong with the code, or could it be a server issue?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T16:19:17+00:00Added an answer on June 4, 2026 at 4:19 pm

    You seem to mostly ignore the count of bytes actually sent/received. Especially writer.Write(buffer); writes the entire buffer, regardless whether it was entirely filled by sock.Receive(buffer); before.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I've developed a system that saves database insert/update commands into a text file
I seem to be encountering an error when reading from a text file. This
I'm trying to parse text-based file attachments (txt, doc, etc...). However, I can't seem
I have two text files that contain columnar data of the variety position -
I am being sent text files saved in ISO 88591-1 format that contain accented
For a current project, we're designing a client desktop application that parses text files
I need to download a zip archive of text files, dispatch each text file
I have a series of large, flat text files that I need to parse
I'm trying to figure out how to stream mp3 files using django. I've used
I have a series of large text files (up to 1 gig) that are

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.