title: C# SocketAsyncEventArgs handling receive and send data
body: <p>I am trying to understand the 'SocketAsyncEventArgs' class in C#. <a href="http://msdn.microsoft.com/en-us/library/system.net.sockets.socketasynceventargs.aspx">http://msdn.microsoft.com/en-us/library/system.net.sockets.socketasynceventargs.aspx</a></p>
  
  <p>I am following this tutorial:
  <a href="http://www.codeproject.com/Articles/83102/C-SocketAsyncEventArgs-High-Performance-Socket-Cod">http://www.codeproject.com/Articles/83102/C-SocketAsyncEventArgs-High-Performance-Socket-Cod</a></p>
  
  <p>Now I am stuck into how I exactly should process data with my server. What I am trying to do is use a SocketAsyncEventArgs for a connected client with an allocated Buffer space of 512 bytes in the BufferManager. Then what I want to do is to decode the byte[] data into my own custom class (ClientPacket) which holds the byte[] for decoding and reading from.</p>
  
  <p>This is all well but my server doesn't always respond with data the question is:</p>
  
  <p>Do I use 1 SocketAsyncEventArgs for the receiving and loop around to process receive data, then allocate a SocketAsyncEventArgs from the pool whenever I need to send then return it on completion?</p>
  
  <p>And how does the SocketAsyncEventArgs know when reading is complete? (when it is finished with the byte[] buffer before it over-writes it with new data) like how is it returned to the pool when done if I don't respond back?</p>