Sorry , I forgot to explain the reason for removing the close(new) .I removed because the connect will always return 0 for success and -1 for error. So when the successful connect the value of new will be 0,and you close the 0 ( it means stdin ).So only those problem were happen .(connect will not return the file descriptor refer : man connect ) .
Then I add the statement
Actually I misplaced this statement .I explained it below .