title: Python 2.7 TCP Sockets: socket.send() that returns zero versus socket.send() that raises socket.error exception?
body: <p>From <a href="http://docs.python.org/2/howto/sockets.html" rel="nofollow">http://docs.python.org/2/howto/sockets.html</a></p>
  
  <blockquote>
    <p>if a socket send or recv returns after handling 0 bytes, the
    connection has been broken.</p>
  </blockquote>
  
  <p>On the other hand, if the remote end of the TCP connection closes (or is killed), and socket.send() is called subsequently, one can see the following socket.error exception</p>
  
  <blockquote>
    <p>socket.error: [Errno 104] Connection reset by peer</p>
  </blockquote>
  
  <p>Now my question is, what is the difference between "<strong>connection has been broken</strong>" and "<strong>Connection reset by peer</strong>". And exactly what is meant by "connection has been broken" == socket.send() returns zero. To me, not being able to send even a single character is as bad as a socket.error exception. Whatever event that causes socket.send to return zero, should have ideally raised a socket.error exception, so that the application does not have to deal with two different things (exception and return value zero).</p>