Question: I am trying to write a tcp socket based server. In python documentation I read, that `recv` on closed socket should raise error. But when a client closes the socket, the server can still `recv` on this socket and gets empty string. Can I assume then, that if `recv` returns empty string on a blocking socket, that this connection broke or was closed?

Answer: 
You have to check if you have received data from the client. If the data variable is empty, you can assume that there isn't a connection, because the client has closed the socket or something was wrong between them. Good examples are in <https://docs.python.org/2/library/socket.html#example> or if you are using python3: <https://docs.python.org/3.5/library/socket.html#example>
You must handle IOError exceptions by codes.

```
except IOError as io_error:
    if io_error.errno == <YOUR CODE>:
        do something

```

See: <https://docs.python.org/2/library/errno.html#module-errno>
for get codes