The listen() call should be moved out of the if statement.