better error handling around sock.sendall