check if connection hasn't been closed before writing anything to socket