Made sure connection is not closed before trying to send data