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 9214435
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:58:23+00:00 2026-06-18T01:58:23+00:00

I am puzzled at why my Socket.BeginSendFile only sends two files async at a

  • 0

I am puzzled at why my Socket.BeginSendFile only sends two files async at a time. I have tested on different computer with the same results.

Socket.BeginSend seems to send all three at once as expected.

I tested connecting three clients to the server. Which works great, all three connect async as expected. Each client (Test100.exe, Test200.exe, Test300.exe in picture) will request a file from either a folder named 100, 200 or 300 from the server depending on the which client connected.

The problem is that Socket.BeginSendFile is only sending max two files at a time onto the stream. As soon as one of the 2 previously called Socket.BeginSendFile have finished. See below;
enter image description here

As soon as one of the first two clients sending finishes the send, the third begins receiving.

enter image description here

Putting some breakpoints into the code, I can tell that all three Socket.BeginSendFile(…) are being called async.

    private static void Send(Socket handler, String data)
    {
        string dateFolder =  data.Replace("<EOF>", "");

        string longFileName = "C:\\"+dateFolder+"\\poopoo.txt";
        string shortFileName = "poopoo.txt";

        // ==== for beginSend
        //byte[] fileData = File.ReadAllBytes(longFileName);
        // ==== for beginSend


        byte[] fileNameByte = Encoding.ASCII.GetBytes(shortFileName);
        byte[] fileInfo = Encoding.ASCII.GetBytes("C:\\Users\\Trim\\Desktop");
        byte[] fileInfoLen = BitConverter.GetBytes(fileInfo.Length); // we know these are ints (4bytes)

        byte[] clientData = new byte[4 + fileNameByte.Length + fileInfoLen.Length + fileInfo.Length];// + fileData.Length + eofByte.Length
        // ==== for beginSend
        //byte[] clientData = new byte[4 + fileNameByte.Length + fileInfoLen.Length + fileInfo.Length + fileData.Length];
        // ==== for beginSend

        byte[] fileNameLen = BitConverter.GetBytes(fileNameByte.Length); // we know these are int (4bytes);

        fileNameLen.CopyTo(clientData, 0);
        fileNameByte.CopyTo(clientData, 4); // room for error file name 4bytes?
        fileInfoLen.CopyTo(clientData, 4 + fileNameByte.Length);
        fileInfo.CopyTo(clientData, 4 + fileNameByte.Length + fileInfoLen.Length);

        // ==== for beginSend
        //fileData.CopyTo(clientData, 4 + fileNameByte.Length + fileInfoLen.Length + fileInfo.Length);
        // ==== for beginSend
        // *** Break point shows all three being called async
        handler.BeginSendFile(longFileName, clientData, null, 0, new AsyncCallback(AsynchronousFileSendCallback), handler);



       // handler.BeginSend(clientData, 0, clientData.Length, 0, new AsyncCallback(SendCallback), handler);


    }

The third Socket.BeginSendFile(…) doesnt actually begin to send the file until one of the first two AsynchronousFileSendCallback methods

    private static void AsynchronousFileSendCallback(IAsyncResult ar)
    {
        // Retrieve the socket from the state object.
        Socket client = (Socket)ar.AsyncState;

        // Complete sending the data to the remote device.
        client.EndSendFile(ar); // **Third** client doesn't actually start receiving his data until EndSendFile is called atleast once.

        Console.WriteLine("Send file to client.");
       // sendDone.Set();
        client.Shutdown(SocketShutdown.Both);
        client.Close();
    }

As I said earlier, if I use Socket.BeginSend the issue goes away. Although I need to be able to use Socket.BeginSendFile because it chunks the file on a separate thread and particularly this line of code byte[] fileData = File.ReadAllBytes(longFileName); used with my Socket.BeginSend structure is unacceptable for large files 🙁

Thank you all very much for your time!

  • 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-18T01:58:24+00:00Added an answer on June 18, 2026 at 1:58 am

    It’s very likely that BeginSendFile uses the Windows API function TransmitFile to do its job. And this API is limited to 2 concurrent transfers on client versions of Windows.

    Workstation and client versions of Windows optimize the TransmitFile function for minimum memory and resource utilization by limiting the number of concurrent TransmitFile operations allowed on the system to a maximum of two. On Windows Vista, Windows XP, Windows 2000 Professional, and Windows NT Workstation 3.51 and later only two outstanding TransmitFile requests are handled simultaneously; the third request will wait until one of the previous requests is completed.

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

Sidebar

Related Questions

This has puzzled me for two days now. I have a LinearLayout like the
I'm a little puzzled with QueryStrings and ActionResult I have a URL coming in
I am a bit puzzled with my Regex results (and still trying to get
I'm a bit puzzled about the conditional operator. Consider the following two lines: Float
I have been puzzled by this for a while now. My question is, how
I am puzzled, I have a call with jQuery using .load to fill a
I was puzzled when this query failed on me: $results = $this->Event->find('first', array('conditions'=>array( 'user_id'
I am puzzled because I cannot figure where my bug/problem is. I have a
I'm puzzled by something in Scala. I seem to have objects that have the
I'm a little puzzled by proguard. I have this setting in my pom.xml Firstly,

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.