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

  • SEARCH
  • Home
  • 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 6867919
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:22:09+00:00 2026-05-27T03:22:09+00:00

Its a very weird thing. I created a client and a server to upload

  • 0

Its a very weird thing.

I created a client and a server to upload and download files. When uploading I can upload a lot of files without a problem but when I download a file the client for turn to not responding and doesn’t show MessageBox.show("Downloaded"); its the first tie to see this :D.

The code that make the problem when used :

private void button3_Click(object sender, EventArgs e)
{
    try
    {
        String fileToDownload = filePathDownload.Text;


        TcpClient clientSocket = new TcpClient(serverIPDownload.Text, 8880);
        NetworkStream networkStream = clientSocket.GetStream();
        ASCIIEncoding asci = new ASCIIEncoding();
        byte[] b = asci.GetBytes(fileToDownload + "?");
        byte[] bb = asci.GetBytes("Download?");
        int thisRead = 0;
        int blockSize = 1024;
        Byte[] dataByte = new Byte[blockSize];

        networkStream.Write(bb, 0, bb.Length);
        networkStream.Flush();
        networkStream.Write(b, 0, b.Length);
        networkStream.Flush();

        using (FileStream fileStream = new FileStream(
            "C:/Users/Laptop/Documents/Downloads/" + fileToDownload, 
            FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None))
        {
            while (true)
            {
                thisRead = networkStream.Read(dataByte, 0, blockSize);

                fileStream.Write(dataByte, 0, thisRead);
                if (thisRead == 0) break;

            }
            MessageBox.Show("File Downloaded");
            fileStream.Close();
        }
    }
    catch (Exception ex) { MessageBox.Show(ex.Message); }
}

Thanks. This maybe off topic but its the problem I faced.

  • 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-05-27T03:22:09+00:00Added an answer on May 27, 2026 at 3:22 am

    Your code appears to be ok, so I suspect the problem is in the Download method you are reading from.

    Also, I would personally move the loop termination (if (thisRead == 0) break;) before the fileStream.Write statement.

    And for production code, I would add some sort of timeout limit so that you don’t end up in an infinite loop.

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

Sidebar

Related Questions

Maybe its a very dumb question but I hope you can give me some
I ran into a very weird problem today. Long story short, my function returns
I recently observed a very weird problem with MediaPlayer playing an mp3 file. I'm
Im having a very weird issue. I have a normal ajax call that upload
It seems to me its very easy to implement an implicit operator versus a
I'm developing a desktop Mac OS X App that saves its very simple data
does anyone know how purevolume.com gets their rounded corners? its very interesting and cross
Very direct question, i need to know if its possible and maybe where to
I think I'm missing something very obvious and its making my brain hurt. class
I have written a very simple control. C# Visual Studio 2008. Its output should

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.