Real integral $\int_{-\infty}^{\infty} \frac{dx}{1+x^2}$ with the help of complex friends

I have to solve the integral $$\int_{-\infty}^{\infty} \frac{dx}{1+x^2}$$ by doing this:

Given a rectangle that is defined by the points $r+i, -r+i,-r-i,r-i$, $r>0$ and $\gamma_r$ is a closed positively oriented curve around the boundary of this rectangle. Then I should proof that $$\lim_{r \rightarrow \infty} \int_{\gamma_r} \frac{1}{z} dz=2\pi i.$$

And by using this, I am supposed to evaluate $$\int_{-\infty}^{\infty} \frac{dx}{1+x^2}.$$

There are two things that look difficult to me, the first one is: Why is there a limit for the first integral? Cause by using Cauchy's integral theorem this should be the same as the integral around the circle $$C: \gamma(t)=|r+i|e^{it}$$ and therefore $$\int_0^{2\pi} \frac{1}{|r+i|e^{it}}^{i|r+i|e^{it}} dt=2 \pi i.$$

So there is no limit necessary, which makes me thinking that this way should be wrong.

The second thing I do not understand is, how both integrals are related to each other?

-
what would be the advantage of a half-circle? – user66906 Jun 18 '13 at 19:48
no problem, thanks for your ideas – user66906 Jun 18 '13 at 19:49
I guess this is a complex analysis exercise. But I can't resist pointing out that the integrand here has an elementary antiderivative. – alex.jordan Jun 18 '13 at 19:51
I think when you will parameterize integrals of $1/z$ over the four sides of the rectangle, the first integral will magically appear. – Start wearing purple Jun 18 '13 at 19:52
I will give it try... – user66906 Jun 18 '13 at 19:56

Let us write down the integrals over the four sides of the rectangle: \begin{align} &I_1=\int_{r-i}^{r+i}\frac{dz}{z}=\int_{-1}^{1}\frac{idt}{r+it},\\ &I_2=\int_{r+i}^{-r+i}\frac{dz}{z}=-\int_{-r}^{r}\frac{dt}{t+i},\\ &I_3=\int_{-r+i}^{-r-i}\frac{dz}{z}=-\int_{-1}^{1}\frac{idt}{-r+it},\\ &I_4=\int_{-r-i}^{r-i}\frac{dz}{z}=\int_{-r}^{r}\frac{dt}{t-i}. \end{align} Next consider the sum $$I_2+I_4=\int_{-r}^{r}\left(\frac{1}{t-i}-\frac{1}{t+i}\right)dt=2i\int_{-r}^r\frac{dt}{1+t^2}.$$ The limit of this sum as $r\rightarrow\infty$ is proportional to the integral we want to find. On the other hand, the limit of $I_1$ and $I_3$ is zero (they are both $O(1/r)$).
Hence we can write $$\lim_{r\rightarrow\infty}(I_1+I_2+I_3+I_4)=2i\int_{-\infty}^{\infty}\frac{dt}{t^2+1}=2\pi i,$$ which gives the answer.