Ensure that the entire frame is written using socket.sendall (#349)

Thanks to @jwestfall69 for his analysis