Move the socket initialization to outer scope.

This guarentees that socket is not null.
Merge pull request #156 from mfriedenhagen/move-socket-initialization-to-outer-scope

Move the socket initialization to outer scope.