title: read messages on a streaming socket in c
body: <p>I'm writing a client server model application, The server sends a lot of messages (with different sizes) on very high rates on a stream connection to the client, The client reads these messages on a buffer larger than the expected message size</p>
  
  <pre><code>while (ret = read (sd, buf, sizeof buf) &gt; 0)
  {
        // decode message here
  }
  </code></pre>
  
  <p>The problem here is that the client may read more than one message on the buffer like that, If I supposed the buffer is B and the messages are M#, It will receive the message as following</p>
  
  <p>|----B----|----B----|----B----|----B----| ....</p>
  
  <p>|-M1--|-M2-|--M3-|-M4-|---M5---|--M6-| ....</p>
  
  <p>which makes the decoding of the message incorrect. So, I want to receive the messages as following (only one message per buffer)</p>
  
  <p>|----B----|----B----|----B----|----B----| ....</p>
  
  <p>|-M1--|,,|-M2-|,,,|--M3-|,,|-M4-| .... (,,, are nothing, just for formatting)</p>
  
  <p>Noting that, I have to use streaming connection and I don't like not use any delimiter between messages</p>