title: WinSock recv() end of message
body: <p>Consider the following scenario:</p>
  
  <p>I have a server and a client, and they communicate in a custom defined application protocol.
  A typical conversation is like this: (Assuming a connection between the two)</p>
  
  <ol>
  <li>Client sends message to server, and waits for acknowledgment (don't
  confuse with TCP) that it's message has been processed</li>
  <li>Server parses the message and as soon as it reached the end it sends
  an acknowledgment back to the client that it has processed it's
  message </li>
  <li>Client gets the acknowledgment and can now freely send another
  message and wait again for an acknowledgment etc etc.</li>
  </ol>
  
  <p>I have come to a problem implementing this. I am looping <code>recv()</code> parsing the message but as soon as recv has nothing more to return it <strong>blocks</strong>, and my code can't proceed to argue that I've received the whole message so that it sends an acknowledgment. </p>
  
  <p>I've managed to somehow come around this by sending a message size in the header of the message and counting each time whether I've read as many bytes as the message size, but this is not ideal; what if the client machine bugged and it sent an incorrect size?</p>
  
  <p>Also, I've read in another question that this whole acknowledgment process I'm doing is not necessary when using tcp, and that tcp already does that for you; but isn't the handshake only done once per connection? What if I don't close the connection between the two? Then only one handshake at the creation of the connection would have happened.</p>
  
  <p>Do I have to create a new connection every time I want to be sending something? And isn't the handshake done <strong>before</strong> the data is sent, and only when making the connection? So this might not be what I'm looking for in my case.</p>