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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:21:07+00:00 2026-05-13T20:21:07+00:00

When I call BeginSend on a socket, I pass a delegate which will be

  • 0

When I call BeginSend on a socket, I pass a delegate which will be called (by a different thread) when the data has been sent.

What would happen if I call BeginSend another time while the first has not yet been ‘callbacked’?

What is the correct behavior to send data? do BeginSend, and on the callback do EndSend and start another send? Or is it actually wise to have multiple BeginSends working at the same time?

this is the BeginSend page on MSDN which doesn’t give an answer to this question: BeginSend msdn

  • 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-13T20:21:07+00:00Added an answer on May 13, 2026 at 8:21 pm

    As O.K.W. says, multiple pending BeginSend calls will work fine. You probably DO need to bear in mind some things though.

    Firstly if this is a TCP socket then this is still a single stream of data from peer to peer.

    Secondly if all your BeginSend calls occur on the same thread then the result will be that the peer receives the data in the order of the calls. If your BeginSend calls occur from different threads then the data could arrive in any order as there will likely be a race condition between each of the sends. This may or may not matter to you (depends if you’re sending discrete, complete messages with each send or not).

    Thirdly if you are using TCP and sending faster than the code at the other end of the socket can receive then you may fill the TCP Window and the TCP stacks will start to perform flow control on your data stream. If you continue to issue BeginSend calls then you MAY end up in a situation where your callbacks take longer and longer to be called as the TCP stack on your server queues data to send (you only get the callback once the data has been sent and the TCP Window based flow control will be preventing new data being sent until the TCP Window is no longer ‘full’; i.e. the peer has sent ACKs for some of the data that is in flight).

    You can then get into a situation whereby you are using up resources on the sending machine in an uncontrollable manner (you issue a BeginSend and have no idea when it will complete and each send uses memory for the buffer being sent and potentially non-paged pool down in the Winsock code… Non-paged pool is a system wide resource and is quite a scarce on pre Vista OSs and some badly behaved drivers can blue screen the box if non-paged pool is low or exhausted. What’s more you may also be locking pages of memory into memory and there’s another system wide limit on the number of locked memory pages.

    Because of these issues it’s usually best to implement your own protocol level flow control which limits the number of BeginSend calls that can be pending at any one time (using a protocol level ACK, perhaps) or to work with the TCP Window flow control and use the completion of a pending send to issue a new send and you can queue data to send in your own memory and have complete control over the resources used and what you do if you queue “too much” data. See my blog post here for more detail on this: http://www.serverframework.com/asynchronousevents/2011/06/tcp-flow-control-and-asynchronous-writes.html

    See this reply: what happens when tcp/udp server is publishing faster than client is consuming? for more information on TCP Window flow control and what happens with overlapped I/O (in C++ land) when you ignore it and issue too many overlapped sends…

    In summary, posting multiple concurrent BeginSend calls is the way to optimum TCP data flow but you need to make sure you don’t send “too fast” as once you do you are consuming resources in a manner which you can’t control and which is potentially fatal for the machine on which your code is running. So don’t allow an unbounded number of BeginSend calls to be outstanding and, ideally, profile the box to ensure that you are not exhausting system wide resources.

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

Sidebar

Related Questions

Consider the Socket.BeginSend() method. If two thread pool threads were to call this method
I need to read from NetworkStream which would send data randomly and the size
When doing a begin... async call, the delegate I pass is handled (according to
Call me stupid but this thing has been eating away my productive time like
I call a jasper report through an independent URL through which I pass one
AJAX Call $.ajax({ url: '/api/Inventory', cache: false, type: 'POST', data: json, contentType: 'application/json, charset=utf-8',
I am very very new to delegates! I have an AsyncCallback delegate which runs
Call to a member function save() on a non-object in .../views/manufacturer/tmpl/edit.php line 24 which
I am attempting to create an application that will call a remote modem and
I call an async method which in turn calls needs to start several async

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.