Do the socket connection in a separate helper function.

Signed-off-by: Thiago Farina <tfarina@chromium.org>