added a check for the return status of recv == 0