Can you explain how this works? I can't see where in the code the socket ends up in a write-only state.