title: Socket Protocol Fundamentals
body: <p>Recently, while reading a <a href="http://www.amk.ca/python/howto/sockets/" rel="noreferrer">Socket Programming HOWTO</a> the following section jumped out at me:</p>
  
  <blockquote>
    <p>But if you plan to reuse your socket for further transfers, you need to realize that there is no "EOT" (End of Transfer) on a socket. I repeat: if a socket send or recv returns after handling 0 bytes, the connection has been broken. If the connection has not been broken, you may wait on a recv forever, because the socket will not tell you that there's nothing more to read (for now). Now if you think about that a bit, you'll come to realize a fundamental truth of sockets: messages must either be <b>fixed length</b> (yuck), or be <b>delimited</b> (shrug), or <b>indicate how long they are</b> (much better), or <b>end by shutting down the connection</b>. The choice is entirely yours, (but some ways are righter than others).</p>
  </blockquote>
  
  <p>This section highlights 4 possibilities for how a socket "protocol" may be written to pass messages. My question is, what is the preferred method to use for real applications? </p>
  
  <p>Is it generally best to include message size with each message (presumably in a header), as the article more or less asserts? Are there any situations where another method would be preferable?</p>