Handle disconnection when sending message

An exception is now thrown if bytes can't be written to the socket, so the client can catch and try to reconnect.