title: Sockets BeginReceive issue
body: <p>Why am I getting an error of <a href="http://msdn.microsoft.com/en-us/library/dxkwh6zw.aspx" rel="nofollow">BeginReceive</a> method of Size (3rd parameter)?</p>
  
  <p>But BUFFER_SIZE its never bigger (in lenght) then the constant value (its 2048 bytes).</p>
  
  <p>This is my code:</p>
  
  <pre><code>public void Send(byte[] byteData, M.StateObject _stateObj, Socket client)
      {
          // Begin sending the data to the remote client(s):
          client.BeginSend(byteData, 0, byteData.Length, 0, new AsyncCallback(SendData), _stateObj);
      }
  
      void SendData(IAsyncResult ar)
      {
          try
          {
              M.StateObject stateObj = (M.StateObject)ar.AsyncState;
              Socket client = stateObj.server;
              byte[] data = stateObj.data;
              int bytesSent = client.EndSend(ar);
              client.BeginReceive(data, 0, M.StateObject.BUFFER_SIZE, SocketFlags.None, new AsyncCallback(ReceiveData), stateObj);
              allDone.Set();
          }
          catch (Exception ex)
          {
              OnMessageShowing(ex.Message);
          }
      }
  
      private void ClientLogging(object _data, M.StateObject _stateObj)
      {
          M.UserData client = _data as M.UserData;
          if (client != null)
          {
              //setting properties:
              client.bConnectred = true;
  
              // 1. add client to list of clients:
              ClientAddingRemoving(_stateObj, client, true);
  
              // 2. showing welcome on server
              OnMessageShowing(client.ServerNotifying());
  
              // 3. refreshing the list of clients on server`s main form
              OnClientsListRefreshing(bll.ClientsListCreating(listOfClients));
  
              // 4. send welcome note to all clients:
              byte[] bytesToSend = M.SerializeServer.Login_WelcomeToAllClients(client);
              bytesToSend = M.BytesArrayGetSet.BytesSending_Set(bytesToSend);
              SendToAll(bytesToSend, _stateObj.server);
  
              // 5. send list of all users to logged client:
              bytesToSend = M.SerializeServer.Login_ToLoggedClient(bll.ListOfAllUsers(listOfClients));
              bytesToSend = M.BytesArrayGetSet.BytesSending_Set(bytesToSend);
              Send(bytesToSend, _stateObj, _stateObj.server);
  
              //6. send new client to list of all other clients:
              bytesToSend = M.SerializeServer.Login_ToAllClients(client);
              bytesToSend = M.BytesArrayGetSet.BytesSending_Set(bytesToSend);
              SendToAll(bytesToSend, _stateObj.server);
          }
      }
  
      private void SendToAll(byte[] data, Socket _socket)
      {
          foreach (M.StateObject stObj in listOfClients.Keys) //dictionary&lt;StateObject, Client&gt;, Client is a custom client class
          {
              Send(data, stObj, _socket);
          }
      }
  </code></pre>
  
  <p>Here is the StateObject class:</p>
  
  <pre><code>public class StateObject 
  {    
      public Socket Server;
      public const int BUFFER_SIZE = 2048;
      public byte[] data = new byte[BUFFER_SIZE];
  }
  </code></pre>
  
  <p>Maybe calling Send() method too many times? Do I have to use "ManualResetEvent" delegate to block or to do something else? I really dont know what to do.</p>