title: C# Sockets. Sending data through TCP/IP on slow connections
body: <p>I have a TCP/IP connection between a server and a client. Once the connection is established, the server will start sending a lot of data to the client. The problem that I'm having is if the connection is slow, at some point the server will become unresponsive. I guess this is because it's buffering data waiting for the data that has already been sent to be acknowledged.</p>
  
  <p>Is there are way before trying to send data to check the size of the current buffer, so I know I should wait before continuing sending data?</p>
  
  <p>Thanks.</p>
  
  <p>This is what I'm doing to send data:</p>
  
  <pre><code>System.Net.Sockets.Socket ClientSocket;
  ...  
  public void Send(byte[] data, int size)
      {
          try
          {
              SocketAsyncEventArgs e = new SocketAsyncEventArgs();
              e.SetBuffer(data, 0, size);
              bool pending = ClientSocket.SendAsync(e);
          }
          catch (Exception ex)
          {
  
          }
      }
  </code></pre>
  
  <p></p>